diff options
author | Stephane Glondu <steph@glondu.net> | 2021-11-28 17:33:21 +0100 |
---|---|---|
committer | Stephane Glondu <steph@glondu.net> | 2021-11-28 17:33:21 +0100 |
commit | d17c0b50eced85a5030a91e3c2d319a76ca4ad0d (patch) | |
tree | ff6615135ce8186e885c001e689a45b1c19a7a46 | |
parent | 7bdd8bf6a87ebf7c55816ffc843fc58db8dcc981 (diff) |
New upstream version 0.9.1
-rw-r--r-- | .github/workflows/ci.yml | 2 | ||||
-rw-r--r-- | .travis.yml | 10 | ||||
-rw-r--r-- | CHANGES | 6 | ||||
-rw-r--r-- | dune-project | 6 | ||||
-rw-r--r-- | duppy.opam | 7 | ||||
-rw-r--r-- | src/duppy.ml | 28 | ||||
-rw-r--r-- | src/duppy.mli | 2 |
7 files changed, 38 insertions, 23 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6aa2a7b..5f6a8f0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: steps: - uses: actions/checkout@v1 - name: Setup OCaml - uses: avsm/setup-ocaml@v1.0 + uses: avsm/setup-ocaml@master - name: Install depext module run: opam install -y depext - name: Pin locally diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 40499dc..0000000 --- a/.travis.yml +++ /dev/null @@ -1,10 +0,0 @@ -language: c -sudo: false -addons: - apt: - sources: - - avsm - packages: - - opam - -script: bash -ex .travis-ci.sh @@ -1,3 +1,9 @@ +0.9.1 (06-21-2021) +===== +* Make `stop` synchronous, waiting for all tasks to stop + while sending `Condition.signal`. Should avoid potential + race-conditions when signaling tasks to end. + 0.9.0 (07-10-2020) ===== * Add offset/length to writing functions. diff --git a/dune-project b/dune-project index 52847a2..ab3bc8a 100644 --- a/dune-project +++ b/dune-project @@ -1,5 +1,5 @@ -(lang dune 2.0) -(version 0.9.0) +(lang dune 2.7) +(version 0.9.1) (name duppy) (source (github savonet/ocaml-duppy)) (license GPL-2.0) @@ -12,6 +12,6 @@ (name duppy) (synopsis "Library providing monadic threads") (depends - (dune (> 2.0)) + dune pcre) ) @@ -1,6 +1,6 @@ # This file is generated by dune, edit dune-project instead opam-version: "2.0" -version: "0.9.0" +version: "0.9.1" synopsis: "Library providing monadic threads" maintainer: ["The Savonet Team <savonet-users@lists.sourceforge.net>"] authors: ["Romain Beauxis <toots@rastageeks.org>"] @@ -8,11 +8,12 @@ license: "GPL-2.0" homepage: "https://github.com/savonet/ocaml-duppy" bug-reports: "https://github.com/savonet/ocaml-duppy/issues" depends: [ - "dune" {> "2.0"} + "dune" {>= "2.7"} "pcre" + "odoc" {with-doc} ] build: [ - ["dune" "subst"] {pinned} + ["dune" "subst"] {dev} [ "dune" "build" diff --git a/src/duppy.ml b/src/duppy.ml index 59697cf..e0bb6e6 100644 --- a/src/duppy.ml +++ b/src/duppy.ml @@ -76,6 +76,7 @@ type 'a scheduler = { queues_m : Mutex.t; mutable stop : bool; stop_m : Mutex.t; + queue_stopped_c : Condition.t; } let clear_tasks s = @@ -98,6 +99,7 @@ let create ?(compare = compare) () = queues_m = Mutex.create (); stop = false; stop_m = Mutex.create (); + queue_stopped_c = Condition.create (); } let wake_up s = ignore (Unix.write s.in_pipe (Bytes.of_string "x") 0 1) @@ -171,10 +173,15 @@ let stop s = Mutex.lock s.stop_m; s.stop <- true; Mutex.unlock s.stop_m; - wake_up s; - Mutex.lock s.ready_m; - List.iter Condition.signal s.queues; - Mutex.unlock s.ready_m + Mutex.lock s.queues_m; + while List.length s.queues > 0 do + wake_up s; + Mutex.lock s.ready_m; + List.iter Condition.signal s.queues; + Mutex.unlock s.ready_m; + Condition.wait s.queue_stopped_c s.queues_m + done; + Mutex.unlock s.queues_m let tmp = Bytes.create 1024 @@ -337,7 +344,18 @@ let queue ?log ?(priorities = fun _ -> true) s name = end; (f [@tailcall]) () in - try f () with Queue_stopped -> () + let on_done () = + Mutex.lock s.queues_m; + s.queues <- List.filter (fun q -> q <> c) s.queues; + Condition.signal s.queue_stopped_c; + Mutex.unlock s.queues_m + in + ( try f () with + | Queue_stopped -> () + | exn -> + on_done (); + raise exn ); + on_done () module Async = struct (* m is used to make sure that diff --git a/src/duppy.mli b/src/duppy.mli index 0c1cf0e..be0a4d6 100644 --- a/src/duppy.mli +++ b/src/duppy.mli @@ -83,7 +83,7 @@ val queue : string -> unit -(** Stop all queues running on that scheduler, causing them to return. *) +(** Stop all queues running on that scheduler and wait for them to return. *) val stop : 'a scheduler -> unit (** Core task registration. |