Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming

Reply
 
LinkBack Thread Tools
Old 05-28-08   #1 (permalink)
Apple Doesn't Love You
 
rabidgnome229's Avatar
 
intel nvidia

Join Date: Feb 2006
Location: Pittsburgh
Posts: 4,950
Blog Entries: 1

Rep: 558 rabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famous
Unique Rep: 0
FAQs Submitted: 6
Trader Rating: 5
Default Signals with Threads

I have a process with multiple threads running. If one thread sends a signal to the process, will every thread see the signal? If not which thread will? Are signals thread-safe?
__________________
BIG BROTHER
I put on my robe and wizard hat...

IS WATCHING

System: It goes to eleven
CPU
E6300
Motherboard
DS3
Memory
2GB XMS2 DDR2-800
Graphics Card
EVGA 8600GTS
Hard Drive
1.294 TB
Sound Card
Audigy 2 ZS
Power Supply
Corsair 520HX
Case
Lian-Li v1000B Plus
CPU cooling
TTBT
GPU cooling
Thermalright V2
OS
Arch Linux/XP
Monitor
Samsung 226bw
rabidgnome229 is online now Overclocked Account   Reply With Quote
Old 05-29-08   #2 (permalink)
New to Overclock.net
 
Join Date: May 2008
Location: Nottingham, UK
Posts: 24

Rep: 7 Stormwolf Unknown
Unique Rep: 0
Trader Rating: 0
Default

Well seeing as no-one else seems to be answering, I'll give it a go... I'm kinda learning this stuff myself at the moment in my (limited) spare time but here's what I think I've understood so far (picking stuff up from various sites).

If anyone who knows this stuff thinks I've made a mistake please let me know... always happy to learn I'm assuming you're using Unix / Linux or BSD/MacOS here - Windows has a completely different (and more simple) model.

First rule for implementing signal handlers: don't make any assumptions about which thread is handling the signal.

In a single-threaded application, all signal handlers run on the main thread. In a multithreaded application, signals that are not tied to a specific hardware error (such as an illegal instruction) get delivered to whichever thread happens to be running at the time.

If multiple threads are running simultaneously, the signal is delivered to whichever one the system happens to pick - it's completely arbitrary. i.e. signals can be delivered to any active thread of your application.

If a specific thread wants to handle a given signal, you need to work out some way of notifying that thread when the signal arrives. You cannot assume that installation of a signal handler from that thread will result in the signal being delivered to the same thread.

If you only want some threads to be able to handle the signal, and you want to disable it for the rest, you can use pthread_sigmask(). If you need it to be delivered to a specific worker thread, all the other threads must be masked. To disable the handling of a signal altogether, you can use sigprocmask().

No... I changed my mind - the first rule of signal handling is that signals and multiple threads are a bad combo and should be avoided like the plague

Anyway hope that was some help and you're not more confused than me now.

Incidentally, I just found this
http://softwareblogs.intel.com/2006/...posix-threads/
Stormwolf is offline   Reply With Quote
Old 05-30-08   #3 (permalink)
Apple Doesn't Love You
 
rabidgnome229's Avatar
 
intel nvidia

Join Date: Feb 2006
Location: Pittsburgh
Posts: 4,950
Blog Entries: 1

Rep: 558 rabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famous
Unique Rep: 0
FAQs Submitted: 6
Trader Rating: 5
Default

Quote:
Originally Posted by Stormwolf View Post
Well seeing as no-one else seems to be answering, I'll give it a go... I'm kinda learning this stuff myself at the moment in my (limited) spare time but here's what I think I've understood so far (picking stuff up from various sites).

If anyone who knows this stuff thinks I've made a mistake please let me know... always happy to learn I'm assuming you're using Unix / Linux or BSD/MacOS here - Windows has a completely different (and more simple) model.

First rule for implementing signal handlers: don't make any assumptions about which thread is handling the signal.

In a single-threaded application, all signal handlers run on the main thread. In a multithreaded application, signals that are not tied to a specific hardware error (such as an illegal instruction) get delivered to whichever thread happens to be running at the time.

If multiple threads are running simultaneously, the signal is delivered to whichever one the system happens to pick - it's completely arbitrary. i.e. signals can be delivered to any active thread of your application.

If a specific thread wants to handle a given signal, you need to work out some way of notifying that thread when the signal arrives. You cannot assume that installation of a signal handler from that thread will result in the signal being delivered to the same thread.

If you only want some threads to be able to handle the signal, and you want to disable it for the rest, you can use pthread_sigmask(). If you need it to be delivered to a specific worker thread, all the other threads must be masked. To disable the handling of a signal altogether, you can use sigprocmask().

No... I changed my mind - the first rule of signal handling is that signals and multiple threads are a bad combo and should be avoided like the plague

Anyway hope that was some help and you're not more confused than me now.

Incidentally, I just found this
http://softwareblogs.intel.com/2006/...posix-threads/
That's pretty much what I thought - I had just heard some differing things and wanted to be sure. Condition variables are better suited to this particular problem anyway, I was just wondering about how signals worked in a multithreaded environment
__________________
BIG BROTHER
I put on my robe and wizard hat...

IS WATCHING

System: It goes to eleven
CPU
E6300
Motherboard
DS3
Memory
2GB XMS2 DDR2-800
Graphics Card
EVGA 8600GTS
Hard Drive
1.294 TB
Sound Card
Audigy 2 ZS
Power Supply
Corsair 520HX
Case
Lian-Li v1000B Plus
CPU cooling
TTBT
GPU cooling
Thermalright V2
OS
Arch Linux/XP
Monitor
Samsung 226bw
rabidgnome229 is online now Overclocked Account   Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -4. The time now is 11:05 AM.


Overclock.net is a Carbon Neutral Site Creative Commons License Internet Security By ControlScan

Terms of Service / Forum Rules | Privacy Policy | Advertising | Become an Official Vendor
Copyright © 2008 Shogun Interactive Development. Most rights reserved.
Page generated in 0.15767 seconds with 9 queries