caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* timer
@ 2005-01-03  1:58 Anastasia Gornostaeva
  2005-01-04  1:11 ` [Caml-list] timer SooHyoung Oh
  0 siblings, 1 reply; 10+ messages in thread
From: Anastasia Gornostaeva @ 2005-01-03  1:58 UTC (permalink / raw)
  To: caml-list

Hello.

Does exist Timer module, that allows me add/reset/remove timed events?
Currently I use Unix.setitimer() for my simple implementation that allows
only adding new events into a queue, but my skills is not enough to implement
reset and remove events from the Timer queue.
And I'm not sure if using Unix.sleep() with setitimer() is safely (without
Threads).
Thanks.

ermine


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Caml-list] timer
  2005-01-03  1:58 timer Anastasia Gornostaeva
@ 2005-01-04  1:11 ` SooHyoung Oh
  2005-01-31 19:33   ` Anastasia Gornostaeva
  0 siblings, 1 reply; 10+ messages in thread
From: SooHyoung Oh @ 2005-01-04  1:11 UTC (permalink / raw)
  To: Anastasia Gornostaeva; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 2169 bytes --]

I have one at http://pllab.kaist.ac.kr/~shoh/ocaml/libs/timer/ .


  Module Timer
  <http://pllab.kaist.ac.kr/%7Eshoh/ocaml/libs/timer/doc/type_Timer.html>


module Timer: |sig| .. <http://pllab.kaist.ac.kr/%7Eshoh/ocaml/libs/timer/doc/Timer.html> |end|

timer library. This library uses Sys module and unix, thread library.
------------------------------------------------------------------------

type ||id 

callback id. This is returned from registering timer callback and used 
for unregistering.

val init : |?tck_unit:float -> unit -> unit|

initializer timer library. This should be called before calling any 
timer function.

|tck_unit| : tick unit of tick timer. (default value is 100 milli seconds)

val reset : |unit -> unit|

reset timer library. Timer functions can be called anymore.

val register : |(unit -> unit) -> float -> float -> id <http://pllab.kaist.ac.kr/%7Eshoh/ocaml/libs/timer/doc/Timer.html#TYPEid>|

register callback. /register f start interval/ registers callback 
fucntion /f/ which will be called after /start/ milli seconds at first 
and every /interval/ milli seconds after the first calling. If 
/interval/ is zero, the callback function is called only once.
*Returns* id the registered callback id.

val unregister : |id <http://pllab.kaist.ac.kr/%7Eshoh/ocaml/libs/timer/doc/Timer.html#TYPEid> -> unit|

unregister callback.

val msleep : |float -> unit|

sleep for the given time in milli seconds.

Anastasia Gornostaeva ? ?:

>Hello.
>
>Does exist Timer module, that allows me add/reset/remove timed events?
>Currently I use Unix.setitimer() for my simple implementation that allows
>only adding new events into a queue, but my skills is not enough to implement
>reset and remove events from the Timer queue.
>And I'm not sure if using Unix.sleep() with setitimer() is safely (without
>Threads).
>Thanks.
>
>ermine
>
>_______________________________________________
>Caml-list mailing list. Subscription management:
>http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
>Archives: http://caml.inria.fr
>Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>Bug reports: http://caml.inria.fr/bin/caml-bugs
>
>  
>

[-- Attachment #2: Type: text/html, Size: 3672 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Caml-list] timer
  2005-01-04  1:11 ` [Caml-list] timer SooHyoung Oh
@ 2005-01-31 19:33   ` Anastasia Gornostaeva
  2005-01-31 21:21     ` Alain Frisch
  2005-02-01  7:50     ` Ville-Pertti Keinonen
  0 siblings, 2 replies; 10+ messages in thread
From: Anastasia Gornostaeva @ 2005-01-31 19:33 UTC (permalink / raw)
  To: SooHyoung Oh; +Cc: caml-list

On Tue, Jan 04, 2005 at 10:11:06AM +0900, SooHyoung Oh wrote:

>  Module Timer
>  <http://pllab.kaist.ac.kr/%7Eshoh/ocaml/libs/timer/doc/type_Timer.html>

This module does not work when is compiled for native-code mode and is linked
with libc_r under FreeBSD 5.x 
As bytecode it works perfectly, but i want native-code.

Executing of native-code test:

bash-2.05b$ ./tst
Sleeping for 1 sec: 1107199242.936151
Waked: 1107199243.038147
Sleeping for 2 sec: 1107199243.038242
Waked: 1107199245.038524
Sleeping for 300 msec: 1107199245.039142
^C

Here it stops and eats CPU up to 99% (it does not hang up). 
I guess it is non-portability of ocaml (i have only 3.08.2)
The same shit happens when I use setitimer: my programs sees 1-3 alrarm
signals and does not see alarms signals anymore.

Any idea?

ermine


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Caml-list] timer
  2005-01-31 19:33   ` Anastasia Gornostaeva
@ 2005-01-31 21:21     ` Alain Frisch
  2005-02-01  7:50     ` Ville-Pertti Keinonen
  1 sibling, 0 replies; 10+ messages in thread
From: Alain Frisch @ 2005-01-31 21:21 UTC (permalink / raw)
  To: caml-list

Anastasia Gornostaeva wrote:
> This module does not work when is compiled for native-code mode and is linked
> with libc_r under FreeBSD 5.x 
> As bytecode it works perfectly, but i want native-code.

It seems that the support for threads is broken in FreeBSD. Maybe this
explains your problems. From GODI FAQ:


----------------------------------------------------------------------
Why are POSIX threads disabled for FreeBSD?
----------------------------------------------------------------------

Because they don't work well enough, i.e. there is a problem in
the threading implementation of FreeBSD.

For a description of the problem, see tickets 1820, 1821 of the O'Caml
bug database:

http://caml.inria.fr/bin/caml-bugs/not%20a%20bug?id=1820;page=47;user=guest
http://caml.inria.fr/bin/caml-bugs/not%20a%20bug?id=1821;page=48;user=guest


-- Alain


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Caml-list] timer
  2005-01-31 19:33   ` Anastasia Gornostaeva
  2005-01-31 21:21     ` Alain Frisch
@ 2005-02-01  7:50     ` Ville-Pertti Keinonen
  2005-02-01 12:22       ` Anastasia Gornostaeva
  1 sibling, 1 reply; 10+ messages in thread
From: Ville-Pertti Keinonen @ 2005-02-01  7:50 UTC (permalink / raw)
  To: Anastasia Gornostaeva; +Cc: caml-list

On Mon, 2005-01-31 at 22:33 +0300, Anastasia Gornostaeva wrote:
> On Tue, Jan 04, 2005 at 10:11:06AM +0900, SooHyoung Oh wrote:
> 
> >  Module Timer
> >  <http://pllab.kaist.ac.kr/%7Eshoh/ocaml/libs/timer/doc/type_Timer.html>
> 
> This module does not work when is compiled for native-code mode and is linked
> with libc_r under FreeBSD 5.x 

Did you intentionally link against libc_r, or are you running a
pre-stable version of 5.x?

libpthread is the default for FreeBSD 5.x since before becoming the
stable branch and 6-current, and it should work correctly (verified for
-current).



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Caml-list] timer
  2005-02-01  7:50     ` Ville-Pertti Keinonen
@ 2005-02-01 12:22       ` Anastasia Gornostaeva
  2005-02-01 14:30         ` Ville-Pertti Keinonen
  0 siblings, 1 reply; 10+ messages in thread
From: Anastasia Gornostaeva @ 2005-02-01 12:22 UTC (permalink / raw)
  To: Ville-Pertti Keinonen; +Cc: caml-list

On Tue, Feb 01, 2005 at 09:50:35AM +0200, Ville-Pertti Keinonen wrote:

> > >  Module Timer
> > >  <http://pllab.kaist.ac.kr/%7Eshoh/ocaml/libs/timer/doc/type_Timer.html>
> > 
> > This module does not work when is compiled for native-code mode and is linked
> > with libc_r under FreeBSD 5.x 
> 
> Did you intentionally link against libc_r, or are you running a
> pre-stable version of 5.x?
> 
> libpthread is the default for FreeBSD 5.x since before becoming the
> stable branch and 6-current, and it should work correctly (verified for
> -current).

I have different FreeBSDs, 5.2rc2 and 5.3-release. 
On 5.2rc2 using libc_r is by default but just now I use libmap.conf only for 
ocaml-compiled programs to use pthreads. 
I still dont believe it is only freebsd related problem if i use 
freebsd 5.2rc2 for long time and with wide range of sowtware without 
problems. For example, on my machine there is running Zope based on python 2.1,
that is linked against libc_r. Well, i dont know if it uses signals ...

How can I reproduce this problem on C? A probram below does not lose signals

#include <signal.h>
#include <stdio.h>

void sig_handler(int s)
{
        // stderr is preferred because it is non-buffered
        fprintf(stderr, "Got signal: %d\n", s);
}

int main(int argc, char ** argv)
{
        printf("Starting...\n");
        signal(SIGALRM, sig_handler);
        signal(SIGUSR1, sig_handler);
        signal(SIGUSR2, sig_handler);
        printf("Handlers installed...\n");
        while(1)
        {
                if(!sleep(5))
                        fprintf(stderr, "tick!\n");
                else
                        perror("sleep");
        }
}

Compilation: 
gcc test.o -o test -pthread
gcc test.o -o test -lc_r
and playing with library mapping in libmap.conf
Using: run it ad manually send killall -SIGALRM test
All is fine.

ermine


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Caml-list] timer
  2005-02-01 12:22       ` Anastasia Gornostaeva
@ 2005-02-01 14:30         ` Ville-Pertti Keinonen
  0 siblings, 0 replies; 10+ messages in thread
From: Ville-Pertti Keinonen @ 2005-02-01 14:30 UTC (permalink / raw)
  To: Anastasia Gornostaeva; +Cc: caml-list

On Tue, 2005-02-01 at 15:22 +0300, Anastasia Gornostaeva wrote:

> I have different FreeBSDs, 5.2rc2 and 5.3-release. 
> On 5.2rc2 using libc_r is by default but just now I use libmap.conf only for 
> ocaml-compiled programs to use pthreads. 

Does it work correctly for you when using libpthread on 5.2rc2 (it
might've still been called libkse)?

Does it work correctly with 5.3-release?  (I'd definitely expect it to.)

> I still dont believe it is only freebsd related problem if i use 
> freebsd 5.2rc2 for long time and with wide range of sowtware without 
> problems. For example, on my machine there is running Zope based on python 2.1,
> that is linked against libc_r. Well, i dont know if it uses signals ...

libc_r works most of the time, including signals, but OCaml makes a
particular misbehavior easy to trigger.

This is getting somewhat off-topic, but it still relates to getting
OCaml programs to work correctly, so...

Based on a quick look at the libc_r sources, it seems that what actually
happens is when entering a signal handler, the signal being delivered is
masked (as is sa_mask), and when leaving the handler, the original
signal mask is restored...as long as it hasn't been changed by the
signal handler.  OCaml always modifies the signal mask inside the
handler.

This seems like a misreading of the standard.  According to SUS3:

    When a signal is caught by a signal-catching function installed
    by sigaction(), a new signal mask is calculated and installed for
    the duration of the signal-catching function (or until a call to
    either sigprocmask() or sigsuspend() is made).

    ...

    If and when the user's signal handler returns normally, the
    original signal mask is restored.

Apparently the author of libc_r interpreted the "or until a call to
either sigprocmask() or sigsuspend() is made" to also cancel the
restoration of the original mask.

If you must use libc_r, the following modification might fix the problem
(disclaimer - I haven't tested it):

--- uthread_sig.c.orig  Wed Dec  3 08:54:40 2003
+++ uthread_sig.c       Tue Feb  1 15:52:53 2005
@@ -1112,12 +1112,14 @@
     struct pthread_signal_frame *psf)
 {
        memcpy(&thread->ctx, &psf->ctx, sizeof(thread->ctx));
+#if 0
        /*
         * Only restore the signal mask if it hasn't been changed
         * by the application during invocation of the signal handler:
         */
        if (thread->sigmask_seqno == psf->saved_state.psd_sigmask_seqno)
+#endif
                thread->sigmask = psf->saved_state.psd_sigmask;
        thread->curframe = psf->saved_state.psd_curframe;
        thread->wakeup_time = psf->saved_state.psd_wakeup_time;
        thread->data = psf->saved_state.psd_wait_data;



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: timer
@ 1996-06-07 22:23 Doug Currie, Flavors Technology, Inc.
  0 siblings, 0 replies; 10+ messages in thread
From: Doug Currie, Flavors Technology, Inc. @ 1996-06-07 22:23 UTC (permalink / raw)
  To: caml-list; +Cc: Bruno Petazzoni


>[English: there is no means to measure elapsed time in Caml Light under PC or
>Macintosh. Is there the necessary C code primitive already written somewhere ?]

I did this for my Mac port of Caml Light 0.7 (which is not the official
port) and for Mac Moscow ML (which is the official port and is based on my
Mac Caml Light 0.7).

In my Mac Caml Light 0.7 and in Mac Moscow ML I implemented three timers:
- elapsed time
- time spent in GC
- time spent in "the cooperative multitasking experience"
and primitives to create additional timers.

To do this, macros to start and stop the various timers must be inserted in
many places in the runtime code. The Caml Light team decided not to include
my stuff, probably because so many changes were required in the source.

If you would like to see how it's done, get the Mac Moscow ML from
<http://www.dina.kvl.dk/~sestoft/mosml.html>. Look at the file runtime.c
and then look for uses of the macros beg_gc_time(), end_gc_time(),
beg_mf_time(), and end_mf_time(). gettimeofday is also implemented there in
e_gettimeofday.c.

e







^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: timer
@ 1996-06-06 16:14 Robbert VanRenesse
  0 siblings, 0 replies; 10+ messages in thread
From: Robbert VanRenesse @ 1996-06-06 16:14 UTC (permalink / raw)
  To: Pierre Weis, caml-list


I have ported part of the Unix library to Windows.  It includes gettimeofday
and all the socket stuff.  I have to put some finishing touches on it, but
will make it available soon.  Unfortunately, I'm gone most of next week, and
very busy this week, but I'll see what I can do.

Robbert

At 09:09 AM 6/4/96 +0200, Pierre Weis wrote:
>
>Date: Mon, 3 Jun 1996 21:52:48 +0100
>To: caml-list@pauillac.inria.fr
>Subject: fonction pour mesurer le temps
>
>[English: there is no means to measure elapsed time in Caml Light under PC or
>Macintosh. Is there the necessary C code primitive already written somewhere ?]
>
>j'avais pose a P.W. la question suivante:
>
>> 1) d'un eleve: existe-t-il une fonction de bibliotheque pour mesurer le
>> temps ecoule?
>
>la reponse de P.W.:
>
>> Elle existe dans la librairie Unix. Sinon il faut e'crire un bout de
>> code C qui la procure...
>
>d'ou une nouvelle question, a destination de la liste: quelqu'un a-t-il
>ecrit cette fonction 1) pour caml-win 2) pour caml-dos 3) pour caml-mac ?
>ceci pour eviter de re-inventer la roue (qui tourne, arf).
>
>amicalement,
>
>Bruno Petazzoni <bpetazzoni@sancerre.ac-idf.jussieu.fr>
>Lyc. M. Berthelot
>94100 SAINT-MAUR
>
>
>
>






^ permalink raw reply	[flat|nested] 10+ messages in thread

* timer
@ 1996-06-04  7:09 Pierre Weis
  0 siblings, 0 replies; 10+ messages in thread
From: Pierre Weis @ 1996-06-04  7:09 UTC (permalink / raw)
  To: caml-list


Date: Mon, 3 Jun 1996 21:52:48 +0100
To: caml-list@pauillac.inria.fr
Subject: fonction pour mesurer le temps

[English: there is no means to measure elapsed time in Caml Light under PC or
Macintosh. Is there the necessary C code primitive already written somewhere ?]

j'avais pose a P.W. la question suivante:

> 1) d'un eleve: existe-t-il une fonction de bibliotheque pour mesurer le
> temps ecoule?

la reponse de P.W.:

> Elle existe dans la librairie Unix. Sinon il faut e'crire un bout de
> code C qui la procure...

d'ou une nouvelle question, a destination de la liste: quelqu'un a-t-il
ecrit cette fonction 1) pour caml-win 2) pour caml-dos 3) pour caml-mac ?
ceci pour eviter de re-inventer la roue (qui tourne, arf).

amicalement,

Bruno Petazzoni <bpetazzoni@sancerre.ac-idf.jussieu.fr>
Lyc. M. Berthelot
94100 SAINT-MAUR





^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2005-02-01 14:31 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-03  1:58 timer Anastasia Gornostaeva
2005-01-04  1:11 ` [Caml-list] timer SooHyoung Oh
2005-01-31 19:33   ` Anastasia Gornostaeva
2005-01-31 21:21     ` Alain Frisch
2005-02-01  7:50     ` Ville-Pertti Keinonen
2005-02-01 12:22       ` Anastasia Gornostaeva
2005-02-01 14:30         ` Ville-Pertti Keinonen
  -- strict thread matches above, loose matches on Subject: below --
1996-06-07 22:23 timer Doug Currie, Flavors Technology, Inc.
1996-06-06 16:14 timer Robbert VanRenesse
1996-06-04  7:09 timer Pierre Weis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).