Subj : Re: Linux pthreads, C-program, how to timeout a thread? To : comp.programming.threads From : Oliver Battenfeld Date : Thu Apr 28 2005 04:10 am fj40rockcrawler@gmail.com wrote: Hi, > The program talks to a serial port with standard Linux read/write > function calls. However, those are blocking calls, like the read, it > will block until there is something to read. [...] > So I could say if the ReadMBThread didn't > complete in 100ms I would terminate it and log and error and go on. [...] > Any ideas? Can you put a timeout on a thread when you create it? at least not on a POSIX thread. Why don't you use select and have it suspend the thread until there actually is some data to read? You can pass a pointer to a struct timeval as a timeout value. When select returns simply use FD_ISSET to check whether there really is something to read() (and then do it), otherwise clean up and exit the thread. -- Bye, Oliver .