File tree Expand file tree Collapse file tree 5 files changed +10
-8
lines changed Expand file tree Collapse file tree 5 files changed +10
-8
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
- Some code snippet regarding concurrency in OCaml.
1
+ Code snippet regarding concurrency (Mutex, Condition, Thread) in OCaml.
2
2
3
3
- ` pro_con.ml ` : Producers-Consumers Problem
4
4
- ` concurrency.ml ` and ` bank.ml ` are from [ CS3110 of Cornell] ( http://www.cs.cornell.edu/courses/cs3110/2013sp/recitations/rec17.html )
5
+
6
+ # Usage
7
+
8
+ ocamlmktop -thread unix.cma threads.cma -o mytop
9
+ ./mytop -I +threads
10
+ # test ();;
11
+
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ let produce () =
12
12
Mutex. lock m2;
13
13
while ! cnt = buffer_size do Condition. wait not_full m2 done ;
14
14
15
- cnt := ! cnt + 1 ;
15
+ incr cnt;
16
16
print_string (" One more item is added to the buffer, now with size " ^
17
17
(string_of_int ! cnt) ^ " \n " );
18
18
flush stdout;
@@ -24,7 +24,7 @@ let consume () =
24
24
Mutex. lock m2;
25
25
while ! cnt = 0 do Condition. wait not_empty m2 done ;
26
26
27
- cnt := ! cnt - 1 ;
27
+ decr cnt;
28
28
print_string (" One more item is removed to the buffer, now with size " ^
29
29
(string_of_int ! cnt) ^ " \n " );
30
30
flush stdout;
You can’t perform that action at this time.
0 commit comments