Rafi Cohen wrote:
Thanks, Guy, I'll try this debugging. Howeer, befor that I want to make
sure I'm using the correct mechanism for timeout.
For example, within the thread that needs to wait 10 seconds, the sample
code is as follows:
struct timespec tmspec;
int retcode;

Clock_gettime(CLOCK_REALTIME, &tmspec);
Tmspec.tv_sec += (seconds to wait until timeout).
Then within the loop: lock mutex, retcode =
pthread_cond_timedwait(&cond, &mutex, &tmspec);
Unlock mutex and then check if retcode == ETIMEDOUT, process on.
Does this seem to be corrct, specifically the seconds I add to
tmspec.tv_sec?

‎this is wrong.

First of all - for any condition variable you take the mutex outside the loop, never inside. Second (probably less important, but not sure) - you compute the timeout inside the mutex and no outside.

Again, instead of asking question on the mailing list you should be reading the fine man page with the extra fine code example in it:

http://linux.die.net/man/3/pthread_cond_timedwait

RTFM! :-)

Gilad


--
Gilad Ben-Yossef <[EMAIL PROTECTED]>
Codefidence. A name you can trust(tm)
Web: http://codefidence.com  | SIP: [EMAIL PROTECTED]
IL: +972.3.7515563 ext. 201  | Fax:            +972.3.7515503
US: +1.212.2026643 ext. 201  | Cel:           +972.52.8260388

        "There once was a virtualization coder,
         Whose patches kept getting older,
         Each time upstream would drop,
         His documentation would slightly rot,
         SO APPLY MY F*$KING PATCHES OR I'LL KEEP WRITING LIMERICKS."
                -- Rusty Russel



================================================================To unsubscribe, 
send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]

Reply via email to