Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0004104OCamlotherlibspublic2006-09-08 21:522016-12-07 16:53
Assigned To 
PlatformOSOS Version
Product Version3.09.3 
Target VersionFixed in Version 
Summary0004104: Condition.timedwait missing in threads library
DescriptionThe POSIX-standard supports the function pthread_cond_timedwait, which would be very useful for many systems applications. The POSIX-threads version is trivial to write (took me only a few minutes) so it would be great if it could be made part of the standard distribution.

I don't know how hard it would be to implement for byte code threads, but most people probably don't care much about the latter anyway so one could just leave it unimplemented for those if it's too time consuming to do right now.
Additional InformationThe function interface (the function returns false on timeouts):

  val timedwait : Condition.t -> Mutex.t -> float -> bool

Here is the C-stub:

  CAMLprim value caml_condition_timedwait(value v_cnd, value v_mtx, value v_timeo)
    CAMLparam2(v_cnd, v_mtx);
      int ret;
      pthread_cond_t *cnd = Condition_val(v_cnd);
      pthread_mutex_t *mtx = Mutex_val(v_mtx);
      double timeo = Double_val(v_timeo);
      struct timespec ts;
      ts.tv_sec = timeo;
      ts.tv_nsec = (timeo - ts.tv_sec) * 1e9;
        ret = pthread_cond_timedwait(cnd, mtx, &ts);
      if (ret == ETIMEDOUT) CAMLreturn(Val_false);
      caml_pthread_check(ret, "Condition.timedwait");

Note that the timeout parameter is an absolute time for good reason (see the man page for this function to know why) so the OCaml-interface should keep this specification.
Attached Files

- Relationships

-  Notes
There are no notes attached to this issue.

- Issue History
Date Modified Username Field Change
2006-09-08 21:52 mottl New Issue
2006-09-11 11:18 doligez Status new => acknowledged
2013-09-04 17:15 doligez Tag Attached: patch
2016-12-07 16:53 shinwell Category OCaml general => OCaml otherlibs
2017-02-23 16:42 doligez Category OCaml otherlibs => otherlibs

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker