[opensuse-programming] POSIX Thread programming question
Hi,
I have a question about POSIX threads programming regarding
the program below. Basically, I have 3 threads that are doing nothing
but printing a message and a 4th thread which continuously loop until
all the other 3 threads terminate. To check that the other 3 threads
terminate properly, the 4th thread make calls to
pthread_getschedparam(). I tested the code on a machine running FreeBSD
5.3 and everything works fine. However, the behavior of the program is
completely different on machines running Linux or Cygwin. The problem
on those machines is that pthread_getschedparam() does not return the
proper error code (ESRCH) even when the thread id that was passed to it
is no longer running. I did notice however, that when I moved the code
for the 4th process into main(), everything works fine, which seems to
suggest that only parent process can access their child threads'
scheduling state. So, my questions are:
1) In the POSIX thread
implementation on Linux/Cygwin, can threads running within the same
process access the scheduling state of their peers via
pthread_getschedparam()?
2) Am I just doing something stupid by calling pthread_getschedparam() within my 4th thread ?
Below is the code in question:
#include
On Tue, 2007-06-26 at 23:50 -0700, Romeo AHOHE wrote:
Hi,
I have a question about POSIX threads programming regarding the program below. Basically, I have 3 threads that are doing nothing but printing a message and a 4th thread which continuously loop until all the other 3 threads terminate. To check that the other 3 threads terminate properly, the 4th thread make calls to pthread_getschedparam(). I tested the code on a machine running FreeBSD 5.3 and everything works fine. However, the behavior of the program is completely different on machines running Linux or Cygwin. The problem on those machines is that pthread_getschedparam() does not return the proper error code (ESRCH) even when the thread id that was passed to it
What does it return instead of ESRCH? As you do a pthread_join after each thread is started, the final thread you start should always find all the other threads are already finished. Is that intended? -- Roger Oberholtzer OPQ Systems / Ramböll RST Ramböll Sverige AB Kapellgränd 7 P.O. Box 4205 SE-102 65 Stockholm, Sweden Tel: Int +46 8-615 60 20 Fax: Int +46 8-31 42 23 --------------------------------------------------------------------- To unsubscribe, e-mail: opensuse-programming+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-programming+help@opensuse.org
participants (2)
-
Roger Oberholtzer
-
Romeo AHOHE