
October 27th, 2004, 11:19 PM
|
 |
Banned ;)
|
|
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
|
|
|
An async signal safe function can execute many instances of the function in parallel.
Say, you have a function func1() that is called every time a certain signal occurs. Now when the signal happens, func1() gets executed and let's say the first thing it does is re-enable the signal handler. Now there's a chance that the signal can be triggered again while the code inside func1() is executing. Let's say the signal occurs again and again func1() is fired off. Now there are two copies of the func1() code running because the signal fired twice. If the function is async signal safe, the second instance of func1() running should not affect any of the running of the first instance of func1() (e.g.) if the second instance sets any variable values, those values will NOT be reflected in the first instance.
Say func1() calls things like fopen(), fclose() etc. within it. These functions are not async-signal-safe because they use some global variables within their code and if two instances of fopen() get triggered simultaneously, one of them may change a global variable that the other has set to some value and thus one instance of fopen() may not work right. This makes func1() also not async-signal-safe because two instances of func1() may not always run successfully in parallel. On the other hand, the kernel I/O functions open(), close() etc. are async thread safe as they don't use global variables in their code and if one instance of open() changes the value of a variable, the other instance doesn't see it. So, if func1() uses open()/close() instead of fopen(), fclose(), then two or more instances can safely run in parallel and hence func1() becomes async-signal-safe.
__________________
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne
Last edited by Scorpions4ever : October 27th, 2004 at 11:22 PM.
|