Home
| Calendar
| Mail Lists
| List Archives
| Desktop SIG
| Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings Linux Cafe | Meeting Notes | Linux Links | Bling | About BLU |
On Tuesday 16 November 2004 9:35 pm, Anthony Gabrielson wrote: > Hello all, > I'm trying to figure out howto resend a signal after I do > something. I have reduced my problem to the attached example. If look > though it the main thread gets a signal and then just tries to resend it > back to the thr thread. It just holds at the wait command... I took a look at your program. The problem is synchronization. First, the mutex should be locked before a condition wait. Main fails to lock and unloack the mutex. Remember that pthread_cond_wait() unlocks the mutex, then reacquires it when it wakes up. So, in your code, the thread acquires the mutex, waits 1 usec, then signals main who is waiting. Main wakes up, tries to reacquire the mutex. Or, the thread sends the signal before main issues the condition wait. I removed the usleep(3), locked the mutex before the pthread create. This will block the child thread. Main then creates the child. The child blocks. Then main waits, and the cond_wait unlocks the mutex. The child wakes up and sends the signal. Main then wakes up and blocks on the mutex from the cond_wait. The child then issues a cond_wait, which unlocks the mutex. Main wakes up, signals the child, releases the mutex. The child wakes up, releases the mutex, and exits. Main then completes the jon and exits. gaf at toulouse:~/src> ./pthrsignal main: wait cond thr: Got Mutex thr: Sent Signal main: got cond main: send cond thr: Got Signal thr: Release Mutex -- Jerry Feldman <gerald.feldman at hp.com> Partner Technology Access Center (contractor) (PTAC-MA) Hewlett-Packard Co. 550 King Street LKG2a-X2 Littleton, Ma. 01460 (978)506-5243 -------------- next part -------------- A non-text attachment was scrubbed... Name: pthrsignal.c Type: text/x-csrc Size: 1131 bytes Desc: not available URL: <http://lists.blu.org/pipermail/discuss/attachments/20041117/278b3718/attachment.bin>
BLU is a member of BostonUserGroups | |
We also thank MIT for the use of their facilities. |