Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > sigaction, muxex, condition variable

Reply
Thread Tools

sigaction, muxex, condition variable

 
 
Mike - EMAIL IGNORED
Guest
Posts: n/a
 
      08-08-2007
In a Posix compliant multi-threaded C++ program,
I would like to use sigaction() to catch SIGTERM,
and from my signal handler, lock a mutex, and
broadcast a condition variable. Is this ok?

Thanks,
Mike.

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      08-08-2007
Mike - EMAIL IGNORED wrote:
> In a Posix compliant multi-threaded C++ program,
> I would like to use sigaction() to catch SIGTERM,
> and from my signal handler, lock a mutex, and
> broadcast a condition variable. Is this ok?


You might be better off asking in a Posix newsgroup.


 
Reply With Quote
 
 
 
 
Mike - EMAIL IGNORED
Guest
Posts: n/a
 
      08-09-2007
On Wed, 08 Aug 2007 18:12:07 -0400, Victor Bazarov wrote:

> Mike - EMAIL IGNORED wrote:
>> In a Posix compliant multi-threaded C++ program,
>> I would like to use sigaction() to catch SIGTERM,
>> and from my signal handler, lock a mutex, and
>> broadcast a condition variable. Is this ok?

>
> You might be better off asking in a Posix newsgroup.


Can you suggest a newsgroup?

 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      08-09-2007
Mike - EMAIL IGNORED wrote:
> On Wed, 08 Aug 2007 18:12:07 -0400, Victor Bazarov wrote:
>
>> Mike - EMAIL IGNORED wrote:
>>> In a Posix compliant multi-threaded C++ program,
>>> I would like to use sigaction() to catch SIGTERM,
>>> and from my signal handler, lock a mutex, and
>>> broadcast a condition variable. Is this ok?

>>
>> You might be better off asking in a Posix newsgroup.

>
> Can you suggest a newsgroup?


One with "posix" in its name, perhaps? Or maybe one
dedicated to your OS...


 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      08-09-2007
On Aug 9, 12:12 am, "Victor Bazarov" <(E-Mail Removed)> wrote:
> Mike - EMAIL IGNORED wrote:


> > In a Posix compliant multi-threaded C++ program,
> > I would like to use sigaction() to catch SIGTERM,
> > and from my signal handler, lock a mutex, and
> > broadcast a condition variable. Is this ok?


> You might be better off asking in a Posix newsgroup.


You're probably right, but there are two C++ questions hidden in
there. The answer to the first is, of course, he can only call
these functions from C++ if the system has taken the necessary
steps so that they will show up as `extern "C"' when included
from a C++ program. (All the systems I know have, but you never
know.) The answer to the second is a bit more direct: according
to the C standard (and this part of the C standard has been
explicitly included by reference in the C++ standard): "If the
signal occurs other than as the result of calling the abort or
raise function, the behavior is undefined if the signal handler
refers to any object with static storage duration other than by
assigning a value to an object declared as volatile
sig_atomic_t, or the signal handler calls any function in the
standard library other than the abort function, or the signal
function with the first argument equal to the signal number
corresponding to the signal that caused the invocation of the
handler." Of course, an implementation may define any undefined
behavior, and Posix does, in fact, define a few additional
things you can do in a signal handler.

There's also a more general programming question involved, more
appropriate to comp.threads than any system specific group. But
the answer is obvious: any attempt to lock a mutex (or acquire a
semaphore, or anything else) from an asynchronous signal
guarantees a potential deadlock. (FWIW: under Posix, you do not
normally use signal handlers in multithreaded code. Posix has
other ways of handling this, that do, or at least can be made to
work.)

--
James Kanze (GABI Software) email:(E-Mail Removed)
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

 
Reply With Quote
 
joe
Guest
Posts: n/a
 
      08-09-2007
On Aug 8, 8:21 pm, Mike - EMAIL IGNORED <(E-Mail Removed)>
wrote:
> On Wed, 08 Aug 2007 18:12:07 -0400, Victor Bazarov wrote:
> > Mike - EMAIL IGNORED wrote:
> >> In a Posix compliant multi-threaded C++ program,
> >> I would like to use sigaction() to catch SIGTERM,
> >> and from my signal handler, lock a mutex, and
> >> broadcast a condition variable. Is this ok?

>
> > You might be better off asking in a Posix newsgroup.

>
> Can you suggest a newsgroup?


I would consider asking in comp.programming.threads. They deal with
threading issues in many OSs.

joe

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with while condition OR condition Bill W. Ruby 13 05-09-2011 09:42 PM
Thread Variable race condition Karan Rajput Ruby 1 01-13-2011 02:24 PM
Differfence in the assignment of a variable to a signal with and without condition filmil VHDL 11 05-25-2007 05:26 PM
Condition outside loop or separate loop for different condition? - Java 12 06-15-2005 08:50 AM
datagrid to generate additional querystring collection item to pull off on the target page for input into a condition statement test variable...?? Hazzard ASP .Net 1 04-02-2004 06:48 PM



Advertisments