![]() |
| | #16 | |
| Registered User Join Date: Feb 2009
Posts: 10
| Quote:
| |
| Abs is offline | |
| | #17 | |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,381
| Quote:
Code: struct pthread_mutex_t
{
volatile sig_atomic_t spinlock;
int lock_count;
int wait_count;
wait_queue_head *waiting_threads;
};
When the process holding the mutex unlocks it, it first locks the spin lock, then decrements the lock_count. If the lock_count becomes zero, it checks the wait count (while still holding the spinlock). If it's greater than zero, it dequeues all the processes on the wait queue and wakes them up, sets the wait_count to zero, decrements the lock_count, then unlocks the spinlock. Being able to do this across processes depends on having a method of placing other processes on the wait queue, and telling them to wake up. On Linux, this is done with futexes. Not all implementations of pthreads support inter-process mutexes, but Linux does.
__________________ "Congratulations on your purchase. To begin using your quantum computer, set the power switch to both off and on simultaneously." -- raftpeople@slashdot | |
| brewbuck is offline | |
| | #18 |
| Registered User Join Date: Mar 2003
Posts: 3,844
| >> Does anyone forsee any problem with this... Not sure what "this" is at this point ![]() You can continue to use signals, just replace the signal handler with "g_time_to_die = 1". Then the controlling loop in dispatcher() would be "while (!g_time_to_die)", or something like that. If you just call _exit() in your signal handler, that's not a "clean" way to die (no atexit handlers are called, resources aren't manually released, etc...). A clean termination would be ideal. gg |
| Codeplug is offline | |
| | #19 |
| Registered User Join Date: Feb 2009
Posts: 10
| yeah...sorry about the vagueness of "this". I was referring to just having the signal handler make the child call _exit when it recieves the signal and then resetting the shared counter back to 0. I know it would be better if they exited normally, but my dispatcher isn't in a loop. Each request that comes in is it's own process and then exits... So the dispatcher right now just takes the request (as the child) determines what kind of request it is, calls the correct function to handle the request and thats about it. So short of checking g_time_to_die between various points of all the functions after my dispatcher is called I'm not seeing another way to truly interrupt and cleanly have the childred cleanly exit. I was also unaware of the atexit function (thanks, that will come in useful later on), and so am not calling any other functions on normal exit. I did notice that _exit closes open file descriptors etc.. which should be enough for what the children are doing. As of now I've been able to successfully load the crap out my hobbled together code and no crashes/problems at all (knock on wood). I may still use a semaphore to wait for the max processes to back down so there is an open slot, and if it waits too long then send the kill with the assumption that all of the currently running children are hosed. But thats for later. Thank you both for all of the great information and insight into what was happening. I don't think I ever would have thought it was problem with my signal handler. Thanks again. |
| Abs is offline | |
![]() |
| Tags |
| linux futex |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Which distribution of Linux should I get? | joshdick | A Brief History of Cprogramming.com | 50 | 01-19-2003 09:26 AM |
| Linux for Windows! | Strut | Linux Programming | 2 | 12-25-2002 11:36 AM |
| Linux? Windows Xp? | VooDoo | Linux Programming | 15 | 07-31-2002 08:18 AM |
| Linux Under Windows | Strut | Linux Programming | 3 | 05-27-2002 08:09 PM |
| linux vs linux? | Dreamerv3 | Linux Programming | 5 | 01-22-2002 09:39 AM |