[#16611] lambda, ->, haskell, and so on — Dave Thomas <dave@...>

This is one of those e-mails that I know from the start to be futile, =20=

148 messages 2008/05/01
[#16661] Re: lambda, ->, haskell, and so on — Paul Brannan <pbrannan@...> 2008/05/05

On Thu, May 01, 2008 at 12:26:47PM +0900, Dave Thomas wrote:

[#16662] Re: lambda, ->, haskell, and so on — "David A. Black" <dblack@...> 2008/05/05

Hi --

[#16663] Re: lambda, ->, haskell, and so on — ts <decoux@...> 2008/05/05

David A. Black wrote:

[#16664] Re: lambda, ->, haskell, and so on — "David A. Black" <dblack@...> 2008/05/05

Hi --

[#16682] Re: lambda, ->, haskell, and so on — ara howard <ara.t.howard@...> 2008/05/08

[#16684] Re: lambda, ->, haskell, and so on — Michael Neumann <mneumann@...> 2008/05/08

ara howard wrote:

[#16687] Re: lambda, ->, haskell, and so on — "David A. Black" <dblack@...> 2008/05/08

Hi --

[#16691] Re: lambda, ->, haskell, and so on — "ara.t.howard" <ara.t.howard@...> 2008/05/08

[#16692] Re: lambda, ->, haskell, and so on — "David A. Black" <dblack@...> 2008/05/08

Hi --

[#16695] Re: lambda, ->, haskell, and so on — "ara.t.howard" <ara.t.howard@...> 2008/05/08

[#16705] Re: lambda, ->, haskell, and so on — Evan Phoenix <evan@...> 2008/05/11

Not to throw the whole thread into a tizzy again, but why again is:

[#16708] Re: lambda, ->, haskell, and so on — Nobuyoshi Nakada <nobu@...> 2008/05/11

Hi,

[#16720] Re: lambda, ->, haskell, and so on — Yukihiro Matsumoto <matz@...> 2008/05/11

Hi,

[#16721] Re: lambda, ->, haskell, and so on — "David A. Black" <dblack@...> 2008/05/12

Hi --

[#16722] Re: lambda, ->, haskell, and so on — Yukihiro Matsumoto <matz@...> 2008/05/12

Hi,

[#16723] Re: lambda, ->, haskell, and so on — Evan Phoenix <evan@...> 2008/05/12

[#16724] Re: lambda, ->, haskell, and so on — Yukihiro Matsumoto <matz@...> 2008/05/12

Hi,

[#16726] Re: lambda, ->, haskell, and so on — Nathan Weizenbaum <nex342@...> 2008/05/12

What about "fn" or "fun", for "function"?

[#16728] Re: lambda, ->, haskell, and so on — Yukihiro Matsumoto <matz@...> 2008/05/12

Hi,

[#16731] Re: lambda, ->, haskell, and so on — Evan Phoenix <evan@...> 2008/05/12

[#16732] Re: lambda, ->, haskell, and so on — Yukihiro Matsumoto <matz@...> 2008/05/12

Hi,

[#16759] Re: lambda, ->, haskell, and so on — "David A. Black" <dblack@...> 2008/05/13

Hi --

[#16766] Re: lambda, ->, haskell, and so on — Yukihiro Matsumoto <matz@...> 2008/05/14

Hi,

[#16784] Re: lambda, ->, haskell, and so on — "David A. Black" <dblack@...> 2008/05/18

Hi --

[#16795] Re: lambda, ->, haskell, and so on — Nate_Wiger@... 2008/05/19

On Wed, 14 May 2008, David A. Black wrote:

[#16797] Re: lambda, ->, haskell, and so on — Yukihiro Matsumoto <matz@...> 2008/05/19

Hi,

[#16798] Re: lambda, ->, haskell, and so on — "Christopher Gill" <gilltots@...> 2008/05/19

how about an uppercase lambda (instead of the usual lowercase one)

[#16802] Re: lambda, ->, haskell, and so on — "Suraj N. Kurapati" <sunaku@...> 2008/05/20

Christopher Gill wrote:

[#16843] Re: lambda, ->, haskell, and so on — "Suraj N. Kurapati" <sunaku@...> 2008/05/22

Suraj N. Kurapati wrote:

[#16846] Re: lambda, ->, haskell, and so on — "Berger, Daniel" <Daniel.Berger@...> 2008/05/22

=20

[#16854] Re: lambda, ->, haskell, and so on — "=?ISO-8859-2?Q?Rados=B3aw_Bu=B3at?=" <radek.bulat@...> 2008/05/22

T24gVGh1LCBNYXkgMjIsIDIwMDggYXQgNTozNyBQTSwgQmVyZ2VyLCBEYW5pZWwgPERhbmllbC5C

[#16857] Re: lambda, ->, haskell, and so on — "Jeremy McAnally" <jeremymcanally@...> 2008/05/23

RXZlbiB0aG91Z2ggSSBzZWUgdGhlIHVzZWZ1bG5lc3MsIHRoYXQncyBqdXN0IHVnbHkuCgotLUpl

[#16874] Re: lambda, ->, haskell, and so on — Nate_Wiger@... 2008/05/23

"Jeremy McAnally" <jeremymcanally@gmail.com> wrote on 05/22/2008 05:35:01=20

[#16875] Re: lambda, ->, haskell, and so on — "Nikolai Weibull" <now@...> 2008/05/23

2008/5/23 <Nate_Wiger@playstation.sony.com>:

[#16886] lambda with normal block syntax — "Eric Mahurin" <eric.mahurin@...>

This patch is an independent but related one to my previous one. It can be

64 messages 2008/05/25
[#16895] Re: [PATCH] lambda with normal block syntax — Nobuyoshi Nakada <nobu@...> 2008/05/26

Hi,

[#16900] Re: [PATCH] lambda with normal block syntax — "Eric Mahurin" <eric.mahurin@...> 2008/05/26

On Sun, May 25, 2008 at 8:19 PM, Nobuyoshi Nakada <nobu@ruby-lang.org>

[#16901] Re: [PATCH] lambda with normal block syntax — Yukihiro Matsumoto <matz@...> 2008/05/26

Hi,

[#16902] Re: [PATCH] lambda with normal block syntax — "Suraj N. Kurapati" <sunaku@...> 2008/05/26

Hi,

[#16903] Re: [PATCH] lambda with normal block syntax — Yukihiro Matsumoto <matz@...> 2008/05/26

Hi,

[#16904] Re: [PATCH] lambda with normal block syntax — Dave Thomas <dave@...> 2008/05/26

[#16905] Re: [PATCH] lambda with normal block syntax — Yukihiro Matsumoto <matz@...> 2008/05/26

Hi,

[#16907] Re: [PATCH] lambda with normal block syntax — Dave Thomas <dave@...> 2008/05/26

[#16912] Re: [PATCH] lambda with normal block syntax — Yukihiro Matsumoto <matz@...> 2008/05/26

Hi,

[#16920] Re: [PATCH] lambda with normal block syntax — David Flanagan <david@...> 2008/05/26

If I may, here are two entries from the ChangeLog file:

[#16922] Re: [PATCH] lambda with normal block syntax — Dave Thomas <dave@...> 2008/05/26

[#16927] Re: [PATCH] lambda with normal block syntax — David Flanagan <david@...> 2008/05/26

Dave Thomas wrote:

[#16928] Re: [PATCH] lambda with normal block syntax — Dave Thomas <dave@...> 2008/05/26

[#16929] Re: [PATCH] lambda with normal block syntax — David Flanagan <david@...> 2008/05/26

Dave Thomas wrote:

[#16931] Re: [PATCH] lambda with normal block syntax — Dave Thomas <dave@...> 2008/05/27

[#16946] Re: [PATCH] lambda with normal block syntax — David Flanagan <david@...> 2008/05/27

Dave Thomas wrote:

[#16947] Re: [PATCH] lambda with normal block syntax — James Gray <james@...> 2008/05/27

On May 27, 2008, at 12:33 PM, David Flanagan wrote:

[#16949] Re: [PATCH] lambda with normal block syntax — David Flanagan <david@...> 2008/05/27

James Gray wrote:

[PATCH] Monotonic timeofday()

From: zimbatm <zimbatm@...>
Date: 2008-05-01 17:45:55 UTC
List: ruby-core #16627
Hi ruby-core.

here I am again, with a new revision of my monotonic patch. I still
hope that one day it will be integrated :)

= Problem

This is a subtle problem that is mostly problematic on long running
processes. If the computer's system clock is set back for a certain
delta, the scheduled threads will wait for that delta time + their
scheduled time before being activated again. This is due to the fact
that they uses the epoch-based gettimeofday() time source.

= Solution

The general solution is to use a monotonic clock because monotonicity
is the guarantee that you won't go back in time. Those clocks are not
epoch-based but it doesn't matter because thread scheduling is only
using deltas of times.

The implemented solution uses the POSIX clock_gettime function, which
has a CLOCK_MONOTONIC flag. clock_gettime(), on most BSD, should be in
the libc. On linux, it is required to link ruby against librt.so,
which is part of the libc6 package. The Darwin (OS X) kernel does not
implement the clock_gettime function. Since clock_gettime() doesn't
guarantee you that your system provides such clock, I also had to add
an init function to check the clock availability, plus the
gettimeofday() fallback.

= Patch

Index: eval.c
===================================================================
--- eval.c	(revision 16252)
+++ eval.c	(working copy)
@@ -28,6 +28,12 @@
 #define EXIT_FAILURE 1
 #endif

+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#include <time.h>
+#include <errno.h>
+#endif
+
 #include <stdio.h>

 #include "st.h"
@@ -1340,6 +1346,7 @@
 void Init_stack _((VALUE*));
 void Init_heap _((void));
 void Init_ext _((void));
+void Init_clock _((void));

 #ifdef HAVE_NATIVETHREAD
 static rb_nativethread_t ruby_thid;
@@ -1382,6 +1389,7 @@
     rb_origenviron = environ;
 #endif

+    Init_clock();
     Init_stack((void*)&state);
     Init_heap();
     PUSH_SCOPE();
@@ -10245,13 +10253,32 @@
     curr_thread->safe = level;
 }

+static int clock_monotonic = 0;
+
+void
+Init_clock()
+{
+#ifdef CLOCK_MONOTONIC
+    struct timespec tp;
+    clock_monotonic = (clock_gettime(CLOCK_MONOTONIC, &tp) == 0);
+#endif
+}
+
 /* Return the current time as a floating-point number */
 static double
 timeofday()
 {
-    struct timeval tv;
-    gettimeofday(&tv, NULL);
-    return (double)tv.tv_sec + (double)tv.tv_usec * 1e-6;
+    if (clock_monotonic) {
+#ifdef CLOCK_MONOTONIC
+        struct timespec tp;
+        clock_gettime(CLOCK_MONOTONIC, &tp);
+        return (double)tp.tv_sec + (double)tp.tv_nsec * 1e-9;
+#endif
+    } else {
+        struct timeval tv;
+        gettimeofday(&tv, NULL);
+        return (double)tv.tv_sec + (double)tv.tv_usec * 1e-6;
+    }
 }

 #define STACK(addr) (th->stk_pos<(VALUE*)(addr) &&
(VALUE*)(addr)<th->stk_pos+th->stk_len)

= QA

Q: on what branch is your code based ?
A: I used the ruby_1_8 branch

Q: timeofday() might be used by some code that needs epoch-based time ?
A: I have grep'ed trough the code but might have missed something

Q: is there a similar solution for windows ?
A: I don't know any Windows API that guarantees clock monotonicity.

Q: why didn't you rename timeofday() ?
A: It would hide the purpose of the patch. It is a good idea although.

Q: how do I know if my ruby instance uses the monotonic clock ? (like
I'm running a rails application on a vserver)
A: use "strace" :) . I don't think there is a Scheduled class where I
could publish that information.

In This Thread

Prev Next