I have a shared resource representing request stats for a web server which forks after an accept call to process client connections. I'd like to print these stats to stderr when a certain signal is caught by the parent process, however the stats struct is protected by a semaphore and I know it is a bad idea to lock/unlock semaphores in a signal handler due to deadlock issues. I've tried to set a flag in the sig handler and print the stats from the parent process when the flag is set by first checking for EINTR after accept() and then checking the flag but this didn't work. Any ideas?
Asked
Active
Viewed 44 times
0
-
So I seem to have figured out a way around this. Basically via turning of auto restart off system calls with sigaction() and checking the return value of accept() for EINTR seems to work. – usddddd Mar 28 '14 at 19:31
1 Answers
0
Instead of taking locks or setting flags in the interrupt handler context, can you read the statistics variable using atomic operations like __sync_fetch_and_add.
__sync_fetch_and_add( stats, 0)

Ashok Vairavan
- 1,862
- 1
- 15
- 21