diff options
author | Xavier Leroy <xavier.leroy@inria.fr> | 2009-04-01 16:08:57 +0000 |
---|---|---|
committer | Xavier Leroy <xavier.leroy@inria.fr> | 2009-04-01 16:08:57 +0000 |
commit | c2bdcafb6ad6280ace7f9f69244412e8d033085c (patch) | |
tree | 77135cd6536b8b367462d8e10f23a7250dd9742d | |
parent | 2da17c49c6b4982fdcc25cb968164e345de27526 (diff) |
Added testfork
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@9217 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r-- | otherlibs/systhreads/Tests/Makefile | 15 | ||||
-rw-r--r-- | otherlibs/systhreads/Tests/testfork.ml | 30 |
2 files changed, 39 insertions, 6 deletions
diff --git a/otherlibs/systhreads/Tests/Makefile b/otherlibs/systhreads/Tests/Makefile index 4d860b3e0..0c38dd7e5 100644 --- a/otherlibs/systhreads/Tests/Makefile +++ b/otherlibs/systhreads/Tests/Makefile @@ -18,27 +18,30 @@ PROGS=test1.byt test2.byt test3.byt test4.byt test5.byt test6.byt \ testio.byt testsocket.byt testsignal.byt testsignal2.byt \ torture.byt +MOREPROGS=testfork.byt + include ../../../config/Makefile CAMLC=../../../boot/ocamlrun ../../../ocamlc -I .. -I ../../unix -I ../../../stdlib CAMLOPT=../../../boot/ocamlrun ../../../ocamlopt -I .. -I ../../unix -I ../../../stdlib -all: $(PROGS) +all: $(PROGS) $(MOREPROGS) -allopt: $(PROGS:.byt=.out) +allopt: $(PROGS:.byt=.out) $(MOREPROGS:.byt=.out) clean: rm -f *.cm* *.byt *.out rm -f $(PROGS:.byt=.ml) -%.byt: ../../threads/Tests/%.ml - cp ../../threads/Tests/$*.ml $*.ml +%.byt: %.ml $(CAMLC) -custom -o $*.byt unix.cma threads.cma $*.ml ../libthreads.a ../../unix/libunix.a -cclib -lpthread -%.out: ../../threads/Tests/%.ml - cp ../../threads/Tests/$*.ml $*.ml +%.out: %.ml $(CAMLOPT) -o $*.out unix.cmxa threads.cmxa $*.ml ../libthreadsnat.a ../../unix/libunix.a -cclib -lpthread +%.ml: ../../threads/Tests/%.ml + cp ../../threads/Tests/$*.ml $*.ml + $(PROGS): ../threads.cma ../libthreads.a $(PROGS:.byt=.out): ../threads.cmxa ../libthreadsnat.a diff --git a/otherlibs/systhreads/Tests/testfork.ml b/otherlibs/systhreads/Tests/testfork.ml new file mode 100644 index 000000000..8256a31ea --- /dev/null +++ b/otherlibs/systhreads/Tests/testfork.ml @@ -0,0 +1,30 @@ +(* POSIX threads and fork() *) + +let compute_thread c = + while true do + print_char c; flush stdout; + for i = 1 to 100000 do ignore(ref []) done + done + +let main () = + ignore(Thread.create compute_thread '1'); + Thread.delay 1.0; + print_string "Forking..."; print_newline(); + match Unix.fork() with + | 0 -> + print_string "In child..."; print_newline(); + Gc.minor(); + print_string "Child did minor GC."; print_newline(); + ignore(Thread.create compute_thread '2'); + Thread.delay 1.0; + print_string "Child is exiting."; print_newline(); + exit 0 + | pid -> + print_string "In parent..."; print_newline(); + Thread.delay 2.0; + print_string "Parent is exiting."; print_newline(); + exit 0 + +let _ = main() + + |