Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Question about signals

Reply
Thread Tools

Question about signals

 
 
root
Guest
Posts: n/a
 
      10-09-2009
Hi

I have a program where there's a main server thread that receives jobs
and then farms them out to worker threads.

Unfortunately there is either a bug or an inconsistency in the jobs data
or something, because quite often the worker thread will try to
dereference NULL. This brings down the whole program.

So what I'd like to do is trap SIGSEGV in the worker threads only (not
the main thread), maybe log the error, but basically have the relevant
thread exit gracefully and not whack the whole process.

Is signal() threadsafe? How can I only catch signals in one thread rather
than for the process as a whole?

Thanks for your help.
 
Reply With Quote
 
 
 
 
BGB / cr88192
Guest
Posts: n/a
 
      10-09-2009

"root" <(E-Mail Removed)> wrote in message
news:haoc2h$8n4$(E-Mail Removed)...
> Hi
>
> I have a program where there's a main server thread that receives jobs
> and then farms them out to worker threads.
>
> Unfortunately there is either a bug or an inconsistency in the jobs data
> or something, because quite often the worker thread will try to
> dereference NULL. This brings down the whole program.
>


errm...

bad "data" should not be the cause of bugs.
try instead fixing the code to not be succeptible to any such bad data.

ideally, code should be written to resist crashing even if it is given
largely random garbage.


so, instead, maybe try to track down the bugs (in a debugger or similar), if
possible, and then work out where the bugs originate, and either fix them,
or at least insert basic sanity checks.


also worth noting:
are pointers being used correctly and in a thread-safe manner?
is locking being used correctly?
making use of 'volatile' in the right places?
....


> So what I'd like to do is trap SIGSEGV in the worker threads only (not
> the main thread), maybe log the error, but basically have the relevant
> thread exit gracefully and not whack the whole process.
>
> Is signal() threadsafe? How can I only catch signals in one thread rather
> than for the process as a whole?
>


personally, I think you are probably trying to solve the wrong problem
here...

more so, this question depends some on the specific OS, which is neither
specified nor necessaily topical here.


> Thanks for your help.



 
Reply With Quote
 
 
 
 
Keith Thompson
Guest
Posts: n/a
 
      10-09-2009
root <(E-Mail Removed)> writes:
> I have a program where there's a main server thread that receives jobs
> and then farms them out to worker threads.
>
> Unfortunately there is either a bug or an inconsistency in the jobs data
> or something, because quite often the worker thread will try to
> dereference NULL. This brings down the whole program.
>
> So what I'd like to do is trap SIGSEGV in the worker threads only (not
> the main thread), maybe log the error, but basically have the relevant
> thread exit gracefully and not whack the whole process.
>
> Is signal() threadsafe? How can I only catch signals in one thread rather
> than for the process as a whole?


Standard C has no support for threads. Try comp.programming.threads,
or perhaps a newsgroup that deals with your system
(comp.unix.programmer if my guess is right).

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      10-10-2009
root wrote:
> Hi
>
> I have a program where there's a main server thread that receives jobs
> and then farms them out to worker threads.
>
> Unfortunately there is either a bug or an inconsistency in the jobs data
> or something, because quite often the worker thread will try to
> dereference NULL. This brings down the whole program.
>
> So what I'd like to do is trap SIGSEGV in the worker threads only (not
> the main thread), maybe log the error, but basically have the relevant
> thread exit gracefully and not whack the whole process.
>
> Is signal() threadsafe? How can I only catch signals in one thread rather
> than for the process as a whole?


1) You have asked a threading question, not a C question.
Try a forum with "thread" in its name, not this one.

2) <off-topic> What you would "like to do" is fundamentally
a Bad Idea, Doomed To Failure, Something That Would Be Imagined
Only By Someone Who Hasn't Thought It Through (tm). </off-topic>

--
Eric Sosman
(E-Mail Removed)lid
 
Reply With Quote
 
Stephen Sprunk
Guest
Posts: n/a
 
      10-10-2009
root wrote:
> Unfortunately there is either a bug or an inconsistency in the jobs data
> or something, because quite often the worker thread will try to
> dereference NULL. This brings down the whole program.
>
> So what I'd like to do is trap SIGSEGV in the worker threads only (not
> the main thread), maybe log the error, but basically have the relevant
> thread exit gracefully and not whack the whole process.
>
> Is signal() threadsafe? How can I only catch signals in one thread rather
> than for the process as a whole?


That is the wrong solution.

The correct solution is to verify each pointer isn't null before
dereferencing it, avoiding the segfault entirely. Then put in the
appropriate logging so that you can figure out why those null pointers
are showing up where you're not expecting them.

<OT>
If you weren't using threads, I'd suggest using a debugger instead of
logging, but I've found that using a debugger on multi-threaded programs
often changes thread scheduling enough that the bug I'm looking for no
longer appears.
</OT>

S

--
Stephen Sprunk "God does not play dice." --Albert Einstein
CCIE #3723 "God is an inveterate gambler, and He throws the
K5SSS dice at every possible opportunity." --Stephen Hawking
 
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
[Question] signals mark C Programming 12 07-27-2009 09:29 AM
Testbench Question: Internal signals. BLF VHDL 6 02-06-2009 02:40 AM
Question about signals Ardni VHDL 4 11-05-2008 08:54 AM
Question to resolved signals, transport delay lundril@gmx.de VHDL 6 05-09-2006 10:43 AM
<signal.h> - question about signals Jackie C Programming 11 08-02-2004 07:09 AM



Advertisments