Skip to content

Commit

Permalink
Ajout de la fonction Thread.id
Browse files Browse the repository at this point in the history
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@679 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
  • Loading branch information
xavierleroy committed Mar 5, 1996
1 parent 5e03e75 commit ee63e8d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
12 changes: 10 additions & 2 deletions otherlibs/threads/scheduler.c
Expand Up @@ -176,9 +176,17 @@ value thread_new(clos) /* ML */
return (value) th;
}

/* Return the thread identifier */

value thread_id(th) /* ML */
value th;
{
return ((struct thread_struct *)th)->ident;
}

/* Return the current time as a floating-point number */

double timeofday()
static double timeofday()
{
struct timeval tv;
gettimeofday(&tv, NULL);
Expand All @@ -190,7 +198,7 @@ double timeofday()
#define FOREACH_THREAD(x) x = curr_thread; do { x = x->next;
#define END_FOREACH(x) } while (x != curr_thread)

void schedule_thread()
static void schedule_thread()
{
thread_t run_thread, th;
fd_set readfds, writefds;
Expand Down
2 changes: 2 additions & 0 deletions otherlibs/threads/thread.ml
Expand Up @@ -39,6 +39,8 @@ external thread_wakeup : t -> unit = "thread_wakeup"
external thread_self : unit -> t = "thread_self"
external thread_kill : t -> unit = "thread_kill"

external id : t -> int = "thread_id"

(* In sleep() below, we rely on the fact that signals are detected
only at function applications and beginning of loops,
making all other operations atomic. *)
Expand Down
22 changes: 12 additions & 10 deletions otherlibs/threads/thread.mli
Expand Up @@ -14,27 +14,31 @@
(* Module [Thread]: user-level lightweight threads *)

type t
(* The type of thread identifiers. *)
(* The type of thread handles. *)

(** Thread creation and termination *)

val new : ('a -> 'b) -> 'a -> t
(* [new funct arg] creates a new thread of control, in which the
function application [funct arg] is executed concurrently
with the other threads of the program. The application of [new]
returns the identifier of the newly created thread.
returns the handle of the newly created thread.
The new thread terminates when the application [funct arg]
returns, either normally or by raising an uncaught exception.
In the latter case, the exception is printed on standard error,
but not propagated back to the parent thread. Similarly, the
result of the application [funct arg] is discarded and not
directly accessible to the parent thread. *)
val self : unit -> t
(* Return the identifier of the calling thread. *)
(* Return the thread currently executing. *)
external id : t -> int = "thread_id"
(* Return the identifier of the given thread. A thread identifier
is an integer that identifies uniquely the thread.
It can be used to build data structures indexed by threads. *)
val exit : unit -> unit
(* Terminate prematurely the calling thread. *)
(* Terminate prematurely the currently executing thread. *)
val kill : t -> unit
(* Terminate prematurely the thread whose identifier is given. *)
(* Terminate prematurely the thread whose handle is given. *)

(** Suspending threads *)

Expand Down Expand Up @@ -84,8 +88,6 @@ val sleep : unit -> unit
[critical_section] and suspending the calling thread is an
atomic operation. *)
val wakeup : t -> unit
(* Reactivate the thread whose identifier is given. This thread
is assumed to be suspended on a call to [sleep], [delay],
[wait_inchan] or [wait_descr]. After the call to [wakeup],
the suspended thread will resume execution at some future time.
[wakeup] does nothing if the thread was not suspended. *)
(* Reactivate the given thread. This thread is assumed to
be suspended on a call to [sleep]. After the call to [wakeup],
the suspended thread will resume execution at some future time. *)

0 comments on commit ee63e8d

Please sign in to comment.