Make Time.now monotonically increasing
--------------------------------------

                 Key: JRUBY-2788
                 URL: http://jira.codehaus.org/browse/JRUBY-2788
             Project: JRuby
          Issue Type: Improvement
    Affects Versions: JRuby 1.1RC3
         Environment: Linux
            Reporter: Wayne Meissner
            Assignee: Vladimir Sizikov
            Priority: Minor
         Attachments: Main.java

Related to JRUBY-2698, on some operating systems (e.g. linux), 
System.nanoTime() is not monotonically increasing.
i.e. with two successive calls to System.nanoTime(), the second call can return 
a value less than the first call.

This makes Time.now run backwards, which people assume should not happen.  
Although its not a valid assumption, especially on multi-cpu machines, people 
write code with that assumption, and jruby can break their code.

The attached code snippet demonstrates one possible workaround - it stores the 
last time retrieved, and only returns the new value from System.nanoTime() if 
it is greater than the stored value.

It has a couple of downsides, namely its more complex, and with multiple 
threads calling it, it will hammer the memory bus as it updates the global 
variable.

It needs someone else to verify that MonoTime.nanoTime() is indeed correct 
under all circumstances.



-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to