Subj : Thread Synchronisation and select() To : comp.programming.threads From : Jason Curl Date : Tue Jul 26 2005 11:59 am Hello, I'm writing a small piece of software with two threads in C (on Linux 2.6.12), one thread manages file I/O and another thread is polling hardware. The thread that is polling hardware needs to notify the other thread when a hardware condition has occurred, so it can send a message over a file descriptor (e.g. socket). At the moment, I use the 'kill()' function in Thread B to raise a signal (SIGUSR1) to break the select() function call in Thread A (as we are waiting indefinitely). I don't believe this is a suitable solution (signals may be raised externally also) and that external processes don't need to raise a condition to this process with the two threads. I've also thought about polling, but the poll time seems rather arbitrary (and against the current philosophy of the software by using select() in the first place). Is there a way to associate a posix mutex, condition variable, etc. to a file descriptor? The hope is that thread B can raise a condition by modifying a file descriptor so that the select() function in Thread A can then wait for. When the condition is triggered, I know precisely what condition occurred by what file descriptor had changed state. I realise this can be done with unix sockets, but does Posix provide something simpler (e.g. associate a condition variable/mutex/semaphore to a file descriptor) Thread A: pthread_create(&bthread, NULL, PportThread, NULL); for (;;) { // Set FD sets &fdread, &fdwrite, &fdoob here .. // Wait for any changes (e.g. we're watching a TCP/IP socket) select(maxfd, &fdread, &fdwrite, &fdoob, NULL); // Check the FD sets and do something .. } Thread B: for (;;) { // Check conditions of parallel port, if pin changes state, // notify Thread A somehow. } Best Regards, Jason. .