File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed
testsuite/tests/lib-threads Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -27,16 +27,21 @@ let server sock =
27
27
ignore(Thread. create serve_connection s)
28
28
done
29
29
30
+ let mutex = Mutex. create ()
31
+ let lines = ref []
32
+
30
33
let client (addr , msg ) =
31
34
let sock =
32
35
Unix. socket (Unix. domain_of_sockaddr addr) Unix. SOCK_STREAM 0 in
33
36
Unix. connect sock addr;
34
37
let buf = Bytes. make 1024 ' ' in
35
38
ignore(Unix. write_substring sock msg 0 (String. length msg));
36
39
let n = Unix. read sock buf 0 (Bytes. length buf) in
37
- print_bytes (Bytes. sub buf 0 n); flush stdout
40
+ Mutex. lock mutex;
41
+ lines := (Bytes. sub buf 0 n) :: ! lines;
42
+ Mutex. unlock mutex
38
43
39
- let _ =
44
+ let () =
40
45
let addr = Unix. ADDR_INET (Unix. inet_addr_loopback, 0 ) in
41
46
let sock =
42
47
Unix. socket (Unix. domain_of_sockaddr addr) Unix. SOCK_STREAM 0 in
@@ -45,6 +50,9 @@ let _ =
45
50
let addr = Unix. getsockname sock in
46
51
Unix. listen sock 5 ;
47
52
ignore (Thread. create server sock);
48
- ignore ( Thread. create client (addr, " Client #1\n " ));
53
+ let client1 = Thread. create client (addr, " Client #1\n " ) in
49
54
Thread. delay 0.05 ;
50
- client (addr, " Client #2\n " )
55
+ client (addr, " Client #2\n " );
56
+ Thread. join client1;
57
+ List. iter print_bytes (List. sort Bytes. compare ! lines);
58
+ flush stdout
You can’t perform that action at this time.
0 commit comments