Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Condition.timedwait missing in threads library #4104

Closed
vicuna opened this issue Sep 8, 2006 · 4 comments
Closed

Condition.timedwait missing in threads library #4104

vicuna opened this issue Sep 8, 2006 · 4 comments

Comments

@vicuna
Copy link

vicuna commented Sep 8, 2006

Original bug ID: 4104
Reporter: @mmottl
Status: acknowledged (set by @damiendoligez on 2006-09-11T09:18:14Z)
Resolution: open
Priority: normal
Severity: feature
Version: 3.09.3
Category: otherlibs
Tags: patch
Monitored by: @mmottl

Bug description

The 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 information

The 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;
enter_blocking_section();
ret = pthread_cond_timedwait(cnd, mtx, &ts);
leave_blocking_section();
if (ret == ETIMEDOUT) CAMLreturn(Val_false);
caml_pthread_check(ret, "Condition.timedwait");
CAMLreturn(Val_true);
}

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.

@xavierleroy
Copy link
Contributor

The main reason against Condition.timedwait was that it was difficult to implement in the VM threads library. Since the VM threads library is now gone, we can reconsider the addition of Condition.timedwait. If anyone cares enough to submit a pull request...

@rixed
Copy link
Contributor

rixed commented Nov 18, 2019

I would be happy to submit a PR filling the void for Unix but I wouldn't be able to implement it for windows.
Would that still be useful?

@xavierleroy
Copy link
Contributor

The Windows implementation doesn't look much more difficult than the Unix implementation, so I'd rather have both at the same time.

@github-actions
Copy link

This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants