Re: Issue with pth_mutex_acquire.
On Fri, Oct 08, 2004 at 10:03:50PM +0530, Vinu V wrote: > > Thanks Jason for the reply. > > But why is this considered not safe. Could this be a little more elaborated ? Asynchronous signal handlers can be executed at any time. This means that you could be part way through locking a mutex in normal (non-signal handler) code, then jump into the signal handler. You might succeed in locking the mutex in the signal handler, but the normal code assumed that the mutex lock operation was atomic, and the signal handler has gone and messed with the mutex behind the normal code's back. Havoc ensues. Pth does not protect against signal handlers in such critical sections of code (mutex locking in this example), because the overhead would be prohibitively expensive. It is your responsibility not to do anything dangerous in the signal handler. In general, threads and signals do not mix well. In practice, it s often necessary to use both, but doing so is a delicate dance. You would be well advised to read a book that covers this issue in some detail. My favorite is "Programming with POSIX Threads", by David Butenhof. Jason __ GNU Portable Threads (Pth)http://www.gnu.org/software/pth/ Development Site http://www.ossp.org/pkg/lib/pth/ Distribution Files ftp://ftp.gnu.org/gnu/pth/ Distribution Snapshots ftp://ftp.ossp.org/pkg/lib/pth/ User Support Mailing List[EMAIL PROTECTED] Automated List Manager (Majordomo) [EMAIL PROTECTED]
RE: Issue with pth_mutex_acquire.
Thanks Jason for the reply. But why is this considered not safe. Could this be a little more elaborated ? Regards Vinu -Original Message- From: Jason Evans [mailto:[EMAIL PROTECTED] Sent: Friday, October 08, 2004 9:37 PM To: [EMAIL PROTECTED] Subject: Re: Issue with pth_mutex_acquire. On Fri, Oct 08, 2004 at 09:27:57PM +0530, Vinu V wrote: > > Hi, > > I am having some problem in using linux signals with Pth threads. > > This is what I have done > > 1. From the main (), I have done a pth_init (). > 2. Spawned two threads from the main(). These two threads just runs in a > while loop with a small delay inside the while loop. > 3. Registered a signal handler for SIGUSR1 signal from main(). I am using > sigaction() system call for registering the signal handler. > 4. main() does a pth_join() on the child thread ids. > > Now from the signal handler for SIGUSR1 I am trying to acquire a mutex > using the pth_mutex_acquire() call. > Whenever the signal handler is executed, the program crashes at the > pth_mutex_acquire() call. > > Does anyone have any idea about why it is crashing while trying to acquire > a mutex from a signal handler ? What you can safely call in a signal handler is extremely limited. Mutex acquisition is definitely not on the list of safe APIs. Jason __ GNU Portable Threads (Pth)http://www.gnu.org/software/pth/ Development Site http://www.ossp.org/pkg/lib/pth/ Distribution Files ftp://ftp.gnu.org/gnu/pth/ Distribution Snapshots ftp://ftp.ossp.org/pkg/lib/pth/ User Support Mailing List[EMAIL PROTECTED] Automated List Manager (Majordomo) [EMAIL PROTECTED] - Disclaimer - "This message(including attachment if any)is confidential and may be privileged.Before opening attachments please check them for viruses and defects.MindTree Consulting Private Limited (MindTree)will not be responsible for any viruses or defects or any forwarded attachments emanating either from within MindTree or outside.If you have received this message by mistake please notify the sender by return e-mail and delete this message from your system. Any unauthorized use or dissemination of this message in whole or in part is strictly prohibited. Please note that e-mails are susceptible to change and MindTree shall not be liable for any improper, untimely or incomplete transmission." -
Re: Issue with pth_mutex_acquire.
On Fri, Oct 08, 2004 at 09:27:57PM +0530, Vinu V wrote: > > Hi, > > I am having some problem in using linux signals with Pth threads. > > This is what I have done > > 1. From the main (), I have done a pth_init (). > 2. Spawned two threads from the main(). These two threads just runs in a > while loop with a small delay inside the while loop. > 3. Registered a signal handler for SIGUSR1 signal from main(). I am using > sigaction() system call for registering the signal handler. > 4. main() does a pth_join() on the child thread ids. > > Now from the signal handler for SIGUSR1 I am trying to acquire a mutex > using the pth_mutex_acquire() call. > Whenever the signal handler is executed, the program crashes at the > pth_mutex_acquire() call. > > Does anyone have any idea about why it is crashing while trying to acquire > a mutex from a signal handler ? What you can safely call in a signal handler is extremely limited. Mutex acquisition is definitely not on the list of safe APIs. Jason __ GNU Portable Threads (Pth)http://www.gnu.org/software/pth/ Development Site http://www.ossp.org/pkg/lib/pth/ Distribution Files ftp://ftp.gnu.org/gnu/pth/ Distribution Snapshots ftp://ftp.ossp.org/pkg/lib/pth/ User Support Mailing List[EMAIL PROTECTED] Automated List Manager (Majordomo) [EMAIL PROTECTED]
