Ooh, this is bad. Good overall idea, but this thing is mixing together
two fundamentally different constructs; threads and forks are *not*
interchangeable. Looking at your sanei_thread implementation reveals
this: you can't drop-in sanei_thread_begin() as a replacement for
fork() because one takes 3 arguments and other takes none.
First a question: why was it that you couldn't use fork() on OS/2?
You mentioned earlier that it was a resource hog; could you be more
specific?
I like the idea of some standard wrappers to handle multitasking stuff
for SANE backends. However, there should be some wrappers for forks,
and wrappers for threads, and some #define's for each platform to
specify if they support one or both (and perhaps neither should be
necessary for a functional backend). (But, I imagine that fork()
and its cousins are quite standardized already.)
Forking creates a whole new process (albeit a copy of the original),
with independent memory space. The only way the new process can
communicate with the old is via pipes and signals (and perhaps shared
memory). If a parent process doesn't wait() for its children to
die, they kind of hang around forever (hoping to someday repore
back that exit code).
Threads are concurrently running functions (execution stacks) running
within the same process memory space. So, threads can eliminate a lot
of overhead by communicating via shared data structures. However, they
often require semaphores to synchronize things, and some system
functions are not thread-safe.
A set of wrappers which mixes the two forces a programmer to live in
the worst of both worlds.
-matt m.
PS:
>I have included also the patches to the Umax backend as example. There
>is only one problem: the call to close(fds[1]), must be avoided when
>using threads. I think it could be removed also on other platforms,
>because file handles are closed automatically at process exit. I have
Is this because close() is not thread-safe?
Doesn't each scan opens a new pipe? If so, then pipes would keep
accumulating until the frontend/backend was killed.
-- Source code, list archive, and docs: http://www.mostang.com/sane/ To unsubscribe: echo unsubscribe sane-devel | mail majordomo@mostang.com