Ajout de la fonction Thread.id

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@679 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
master
Xavier Leroy 1996-03-05 10:12:07 +00:00
parent 5e03e75946
commit ee63e8d356
3 changed files with 24 additions and 12 deletions

View File

@ -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);
@ -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;

View File

@ -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. *)

View File

@ -14,7 +14,7 @@
(* Module [Thread]: user-level lightweight threads *)
type t
(* The type of thread identifiers. *)
(* The type of thread handles. *)
(** Thread creation and termination *)
@ -22,7 +22,7 @@ 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,
@ -30,11 +30,15 @@ val new : ('a -> 'b) -> 'a -> t
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 *)
@ -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. *)