Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

systhread implementation and Thread_exit exception #8110

Closed
vicuna opened this issue Apr 16, 2003 · 1 comment
Closed

systhread implementation and Thread_exit exception #8110

vicuna opened this issue Apr 16, 2003 · 1 comment
Labels

Comments

@vicuna
Copy link

vicuna commented Apr 16, 2003

Original bug ID: 1644
Reporter: administrator
Status: closed
Resolution: fixed
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)

Bug description

Full_Name: Stefano Zacchiroli
Version: 3.06
OS: linux
Submission from: n32d125.cs.unibo.it (130.136.32.125)

OCaml systhread implementation use a code like the following to create new
threads:

try
fn arg; ()
with Thread_exit -> ...

where Thread_exit is an exception hidden from Thread.mli. Thread.exit
implementation is therefore simply:

let exit () = raise Thread_exit

This choices makes really dangerous every "try ... with _ -> ..." usage in
thread code (yes, I know that this is a bad(TM) programming style). I've just
spent a lot of time debugging a problem like this one. Even worst most of the
"with _" weren't in my code but in other ocaml libraries code.

Another problem with this approach is the wrapping of exceptions in other
exception, a commonly used approach (e.g. Pxp_types.At exception of the PXP
parser, but I'm almost sure there is something like that in camlp4 code).

Now, I know that this is not an OCaml bug, but is really annoying for thread
programmers. I'm wondering if there are other possible solutions.

Is it possible to implement the Thread.exit function so that it doesn't raise an
exception but invoke directy pthread_exit and perform the needed clean up?

As a quick fix solution, exporting Thread_exit exception in thread.mli can
permit the programmer to write something like:

try
...
with
| Thread_exit as e -> raise e
| _ -> ...

Thanks in advance,
Cheers

@vicuna
Copy link
Author

vicuna commented Jun 16, 2003

Comment author: administrator

Fixed 2003-06-16 by XL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant