-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add set_uncaught_exception_handler to systhreads (#10469)
- Loading branch information
Showing
6 changed files
with
87 additions
and
3 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
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,37 @@ | ||
(* TEST | ||
flags = "-g" | ||
ocamlrunparam += ",b=1" | ||
* hassysthreads | ||
include systhreads | ||
** bytecode | ||
** native | ||
*) | ||
|
||
(* Testing if uncaught exception handlers are behaving properly *) | ||
|
||
let () = Printexc.record_backtrace true | ||
|
||
exception UncaughtHandlerExn | ||
exception CallbackExn | ||
|
||
let handler exn = | ||
let id = Thread.self () |> Thread.id in | ||
let msg = Printexc.to_string exn in | ||
Printf.eprintf "[thread %d] caught %s\n" id msg; | ||
Printexc.print_backtrace stderr; | ||
flush stderr; | ||
raise UncaughtHandlerExn | ||
|
||
let fn () = Printexc.raise_with_backtrace | ||
CallbackExn | ||
(Printexc.get_raw_backtrace ()) | ||
|
||
let _ = | ||
let th = Thread.create fn () in | ||
Thread.join th; | ||
Thread.set_uncaught_exception_handler handler; | ||
let th = Thread.create fn () in | ||
Thread.join th |
12 changes: 12 additions & 0 deletions
12
testsuite/tests/lib-threads/uncaught_exception_handler.reference
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,12 @@ | ||
Thread 1 killed on uncaught exception Uncaught_exception_handler.CallbackExn | ||
Raised at Uncaught_exception_handler.fn in file "uncaught_exception_handler.ml", line 28, characters 12-113 | ||
Called from Thread.create.(fun) in file "thread.ml", line 47, characters 8-14 | ||
[thread 2] caught Uncaught_exception_handler.CallbackExn | ||
Raised at Uncaught_exception_handler.fn in file "uncaught_exception_handler.ml", line 28, characters 12-113 | ||
Called from Thread.create.(fun) in file "thread.ml", line 47, characters 8-14 | ||
Thread 2 killed on uncaught exception Uncaught_exception_handler.CallbackExn | ||
Raised at Uncaught_exception_handler.fn in file "uncaught_exception_handler.ml", line 28, characters 12-113 | ||
Called from Thread.create.(fun) in file "thread.ml", line 47, characters 8-14 | ||
Thread 2 uncaught exception handler raised Uncaught_exception_handler.UncaughtHandlerExn | ||
Raised at Uncaught_exception_handler.handler in file "uncaught_exception_handler.ml", line 26, characters 2-26 | ||
Called from Thread.create.(fun) in file "thread.ml", line 53, characters 10-41 |