1996-04-29 07:06:05 -07:00
|
|
|
let private_data = (Hashtbl.create 17 : (Thread.t, string) Hashtbl.t)
|
|
|
|
let private_data_lock = Mutex.create()
|
1996-04-02 00:41:32 -08:00
|
|
|
|
|
|
|
let set_private_data data =
|
|
|
|
Mutex.lock private_data_lock;
|
|
|
|
Hashtbl.add private_data (Thread.self()) data;
|
|
|
|
Mutex.unlock private_data_lock
|
|
|
|
|
|
|
|
let get_private_data () =
|
|
|
|
Hashtbl.find private_data (Thread.self())
|
|
|
|
|
|
|
|
let process id data =
|
|
|
|
set_private_data data;
|
|
|
|
print_int id; print_string " --> "; print_string(get_private_data());
|
|
|
|
print_newline()
|
|
|
|
|
|
|
|
let _ =
|
1996-04-29 07:06:05 -07:00
|
|
|
let t1 = Thread.create (process 1) "un" in
|
|
|
|
let t2 = Thread.create (process 2) "deux" in
|
|
|
|
let t3 = Thread.create (process 3) "trois" in
|
|
|
|
let t4 = Thread.create (process 4) "quatre" in
|
|
|
|
let t5 = Thread.create (process 5) "cinq" in
|
1996-04-02 00:41:32 -08:00
|
|
|
List.iter Thread.join [t1;t2;t3;t4;t5]
|
|
|
|
|