[sane-devel] Q: threads and pipes
Hi, On Monday 12 January 2004 20:56, Oliver Rauch wrote: [SNIPSNAP] > > So I think you can't close the pipe in threads. > > > > Bye, > > Henning > > I tried what happens when the pipe is closed when threads are used. > It is better to keep the pipe opened :) indeed it is better ;-) You should always keep in mind, that when using threads you still live in the same process-space - per definition. This means, that nothing will be inheritet like in the fork case. In your reader thread you have the same pipe-descriptors, like in the main programm context. If you close it in the thread, then it's closed for the whole process. That's why I introduced the sanei_thread_is_forked() function. That's also, why the MacOSX guys want to use threads instead of fork, because of the buggy fork implementation, the descriptors are not inheritet to the child process... Good luck... Gerhard
[sane-devel] Q: threads and pipes
On Monday 12 January 2004 20:00, Henning Meier-Geinitz wrote: > Hi, > > On Mon, Jan 12, 2004 at 07:42:42PM +0100, Oliver Rauch wrote: > > Does anyone know how pipes have to be handled with threads?! > > > > when fork() is used then I close the read end in the reader_process a= nd > > the write end in the main process. Should I also do this when working > > with threads or should I keep both ends opened ind both treads? > > I'm using code like this in mustek.c: > > if (sanei_thread_is_forked ()) > { > DBG (4, "reader_process: using fork ()\n"); > close (s->pipe); > s->pipe =3D -1; > } > else > { > DBG (4, "reader_process: using threads\n"); > } > > So I think you can't close the pipe in threads. > > Bye, > Henning I tried what happens when the pipe is closed when threads are used. It is better to keep the pipe opened :) Oliver --=20 http://www.xsane.org http://www.mostang.com/sane http://www.rauch-domain.de mailto:oliver.ra...@rauch-domain.de
[sane-devel] Q: threads and pipes
Hi, On Mon, Jan 12, 2004 at 07:42:42PM +0100, Oliver Rauch wrote: > Does anyone know how pipes have to be handled with threads?! > > when fork() is used then I close the read end in the reader_process and the > write end in the main process. Should I also do this when working with > threads or should I keep both ends opened ind both treads? I'm using code like this in mustek.c: if (sanei_thread_is_forked ()) { DBG (4, "reader_process: using fork ()\n"); close (s->pipe); s->pipe = -1; } else { DBG (4, "reader_process: using threads\n"); } So I think you can't close the pipe in threads. Bye, Henning
[sane-devel] Q: threads and pipes
Hello. Does anyone know how pipes have to be handled with threads?! when fork() is used then I close the read end in the reader_process and t= he write end in the main process. Should I also do this when working with threads or should I keep both ends opened ind both treads? Oliver --=20 http://www.xsane.org http://www.mostang.com/sane http://www.rauch-domain.de mailto:oliver.ra...@rauch-domain.de