-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce a watchdog thread to handle exiting the program more gracef…
…ully.
- Loading branch information
Showing
4 changed files
with
32 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
(* When set to true, all reading threads should stop. *) | ||
let terminate = Atomic.make false | ||
|
||
(* | ||
The watchdog will periodically check that the child process is still alive. | ||
If the child process is gone, then it will set the terminate atomic variable to true. | ||
Threads should be checking for this atomic variable periodically, and shut down gracefully. | ||
Note: It is also possible that the terminate variable is set by a signal handler. | ||
*) | ||
let rec watchdog_func child_alive () = | ||
Unix.sleepf 0.1; | ||
match Atomic.get terminate with | ||
| true -> () | ||
| false -> | ||
if not (child_alive ()) then Atomic.set terminate true | ||
else watchdog_func child_alive () |