Re: PR_WaitCondVar
| Newsgroups | gmane.comp.mozilla.devel.nspr |
|---|---|
| Organization | http://groups.google.com |
| Message-ID | <[email protected]> |
On May 15, 10:48 pm, Wan-Teh Chang <[email protected]> wrote: > Wan-Teh Chang wrote: > > Sabyasachi Ruj wrote: > >> Hello, > >> How can I determine that 'PR_WaitCondVar' returned because of timeout or > >> because it has received the notification? > >> In both cases that function returns PR_SUCCESS. > > >> I've gone through the documentation but do not understand what it meant. > > > It is a design decision that PR_WaitCondVar does not report a timeout. > > If you care about timeout, you must call PR_IntervalNow() before and > > after the PR_WaitCondVar call and see if the elapsed time is greater > > than the timeout. > > > The rationale for the design decision is that it is hard for the > > implementation to report a timeout accurately. > > I added a sentence at the end of the PR_WaitCondVar page to > clarify this, with a link to the PR_IntervalNow page:http://developer.mozilla.org/en/docs/PR_WaitCondVar#Description > > You can find sample code on the PR_IntervalNow page. > > Let me know if the man page or the sample code is still not > clear. > > Wan-Teh- Hide quoted text - > > - Show quoted text - Thanks for the reply. The documentaion is clear enough now. I have two doubts. Consider the code below. Please read that comments in the code. void start1 (void * arg) { int ret = 1; while (1) { printf("\nHello this is thread: 1\n"); PR_Lock(mylock); PRIntervalTime start = PR_IntervalNow(); PR_WaitCondVar(mycond, INTERVAL); /*Let INTERVAL is 1000 */ /* Suppose the above function returned because of recieving signal afrer 999 milli sec*/ PRIntervalTime elapsed = PR_IntervalNow() - start; /* The above function somehow took 1 milli sec to return*/ /* So now 'elapsed' is 1000*/ if (elapsed >= INTERVAL) { /* Then will it enter here? And report 'timed out' instead of 'signaled' ?*/ printf("\nTimed Out\n"); } else { printf("\nSignaled\n"); } PR_Unlock(mylock); } } Second doubt is - say the conditional variable is signaled just at INTERVAL. Then what will happen? BTW: I posted this same message half an hour ago with a MSVC project attached for helping in testing. Till now that message did not appear. May be the attachment was the problem. So poting this message again without attachment. -- Regards, Sabyasachi.