Note: cross posted to mozilla.dev.tech.nspr.
Follow up messages are directed there.

lixiangfeng wrote, On 2008-09-26 01:39:
> Hi,I write a program use mozilla nss .
> 
> My process will scan some variable for a expected value.when the variable 
> equals some value,my process will dosomething.So,I call PR_Sleep(1second) 
> for some time interval.
> 
> When my program run in solaris,some shell-base program run on it,this 
> program will start work at 00:00:00,it will adjust the date of computer to 
> the last day,So,the date of computer will keep in one day.

I think you're saying that your shell program sets the system clock back
24 hours every day at midnight, causing the system to keep re-traversing
the hours of a single date.  (This sounds like something that might have
been done to avoid Y2k problems. :)

Do I understand that correctly?

> In this condition,My Program will hung at PR_Sleep,but why?
> 
> I think, PR_Sleep will calculate the wait time for sleep function, when time 
> just(to the last day or adjust to early),PR_Sleep whill block util to it's 
> schedule time?

Yes, that's basically right.

You'll find relevant code at these URLs:
http://mxr.mozilla.org/security/source/nsprpub/pr/src/pthreads/ptthread.c#783
http://mxr.mozilla.org/security/source/nsprpub/pr/src/md/unix/solaris.c#57

> is it a bug of PR_Sleep? 

The question is: how is PR_Sleep defined to behave when the clock is set
backwards?  Is the present behavior consistent with that definition or not?
If not, then it is a bug.

Some definitions are given at
http://mxr.mozilla.org/security/source/nsprpub/pr/include/prthread.h#260
http://developer.mozilla.org/en/PR_Sleep

Those definitions do not answer the question: what if the system time
is set backwards?

I think the NSPR developers are likely to say that the definition should be:
The behavior is undefined if the system clock is set backwards.

> or my function call problem? Can someone help 
> me?thanks!!!
> 
> 
>     int a = 0;//a will be change by other process or thread
>     //.....
>     while(1){
>     PR_Sleep(10);

I think your program is assuming that the time interval for PR_Sleep
is tenths of a second, or seconds.  But it may be neither.  The way to
sleep for one second is:

       PR_Sleep(PR_SecondsToInterval(1));

But that is not the cause of the problem you reported.

I suggest that you to go https://bugzilla.mozilla.org/ and register your
email address there, then file a bug against product NSPR about this.
That bug will then be the place where this issue will be decided, and
if the NSPR developers decide to change the code, that will be the place
where progress is recorded.

It might be reasonable for PR_Sleep to attempt to detect time going
backwards, and attempt to minimize the effect of that by estimating the
amount of time adjustment and modifying the starting time accordingly.
On the other hand, attempting to minimize the effect of time going
backwards could cause a problem in the following situation:

  - a program tries to sleep for 12 hours
  - 5 minutes later, an operator mistakenly sets the system time back 24
    hours.
  - NSPR detects this and tries to compensate by adjusting the starting
    time backwards.
  - 5 minutes later, an operator corrects the system time by setting it
    forward 24 hours.
  - NSPR is likely to terminate the sleep prematurely in that case.

NSPR could attempt to detect large time offsets in either direction, and
compensate for them, but this might have consequences on overhead and
performance, and might lead to oscillation.

I look forward to seeing your bug report.
_______________________________________________
dev-security mailing list
dev-security@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-security

Reply via email to