Skip to content

Commit 10dbeff

Browse files
author
coderxiang
committed
produers-consumers updated
1 parent 9a7d234 commit 10dbeff

File tree

5 files changed

+10
-8
lines changed

5 files changed

+10
-8
lines changed

Concurrency/.gitignore

Lines changed: 0 additions & 5 deletions
This file was deleted.

Concurrency/README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
Some code snippet regarding concurrency in OCaml.
1+
Code snippet regarding concurrency (Mutex, Condition, Thread) in OCaml.
22

33
- `pro_con.ml`: Producers-Consumers Problem
44
- `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+

Concurrency/a.out

574 KB
Binary file not shown.

Concurrency/mytop

1.48 MB
Binary file not shown.

Concurrency/pro_con.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ let produce () =
1212
Mutex.lock m2;
1313
while !cnt = buffer_size do Condition.wait not_full m2 done;
1414

15-
cnt := !cnt + 1;
15+
incr cnt;
1616
print_string ("One more item is added to the buffer, now with size " ^
1717
(string_of_int !cnt) ^ "\n");
1818
flush stdout;
@@ -24,7 +24,7 @@ let consume () =
2424
Mutex.lock m2;
2525
while !cnt = 0 do Condition.wait not_empty m2 done;
2626

27-
cnt := !cnt - 1;
27+
decr cnt;
2828
print_string ("One more item is removed to the buffer, now with size " ^
2929
(string_of_int !cnt) ^ "\n");
3030
flush stdout;

0 commit comments

Comments
 (0)