Subj : Re: nptl and signals To : comp.programming.threads From : divijbhatt@gmail.com Date : Tue Jul 26 2005 11:17 pm Chris Vine wrote: > divijbhatt@gmail.com wrote: > > > > > > > Joe Seigh wrote: > >> divijbhatt@gmail.com wrote: > >> > Hi, > >> > I am masking the per thread signal mask but when I use sigwait > >> > the signal will be delivered to the process which in turn delivers the > >> > signal to the > >> > threads randomly in a process and that is the rule of NPTL and most > >> > importantly how signal/sigaction will determine that it is the thread > >> > to which the signal has to be delivered. > >> > > >> No, it's the rules of Posix that apply here. I don't know why you're > >> mixing up signals and NPTL. What are you attempting to do with > >> signals and threads? > >> > > Hi, > > See,I whether u r convinced or not that it is the rule of NPTL I am > > gtng the same behaviour on my linux 2.6.10 kernel on FC2 with glibc > > 3.3.3 > > > > 1.I am creating three threads in the main program > > 2.I and setting the time for each thread in thread function using > > setitimer() > > 3.After the expiraton of timer SIGALRM is called which called signal() > > asynchronously > > 4.In signal handler function I am setting the flag > > 5.In main function I am checking that if that flag is 1 then I do some > > work there and again make that flag 0. > > > > But PROBLEM is:-------> > > 1.I am not gtng signals properly in my signal handler function some > > signals are dropping.The signals are deliverd to the threads randomly. > > > > ****I am using sigwait,pthread_sigmask(in main program),sempahore(in > > signal handler) also. > > If you are using sigwait() (which is the best way of dealing with signals in > a multi-threaded program) why do you have a signal handler? If you use > sigwait() then all the threads should be blocked to the signal in question, > and sigwait() will act on the signal. > > There seems to be something wrong with your design. > > You may want to look at the documentation for the pthread_sigmask() function > call at http://www.unix.org/single_unix_specification/ , which gives an > example of how to program for signals in a multi-threaded program. > > This approach will not work correctly with linuxthreads, as it does not > deliver signals correctly in conformity with POSIX. However, if you are > using NPTL it will be OK. > > Chris Hi, Chris I have seen that link instead I have put the pthread_sigmask before creating the threads but my program blocks.So, I put them after creating the threads where I am checking the flags just before that. I think there is some problem with design also but tell me I am using sigwait for blocked signals when those signals will be dilevered to the calling thread then signal handler function willn't be executed? I am making the flag 1 in that signal handler function that's why I need that function to be worked upon. Divij .