From c5b5811c3f6f6621dde2ea7577be26b9e565eca7 Mon Sep 17 00:00:00 2001 From: simonmar <unknown> Date: Tue, 6 Jul 1999 15:24:01 +0000 Subject: [PATCH] [project @ 1999-07-06 15:24:01 by simonmar] Add a note about @raiseInThread@. --- ghc/docs/users_guide/parallel.vsgml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/ghc/docs/users_guide/parallel.vsgml b/ghc/docs/users_guide/parallel.vsgml index 05e74c1e151e..a30120c0a54c 100644 --- a/ghc/docs/users_guide/parallel.vsgml +++ b/ghc/docs/users_guide/parallel.vsgml @@ -85,6 +85,26 @@ isn't lost: the computation is suspended until required by another thread. The memory used by the thread will be garbage collected if it isn't referenced from anywhere else. +More generally, an arbitrary exception may be raised in any thread for +which we have a <tt/ThreadId/, with <tt/raiseInThread/: + +<tscreen><verb> +raiseInThread :: ThreadId -> Exception -> IO () +</verb></tscreen> + +Actually <tt/killThread/ just raises the <tt/ThreadKilled/ exception +in the target thread, the normal action of which is to just terminate +the thread. The target thread will stop whatever it was doing (even +if it was blocked on an <tt/MVar/ or other computation) and handle the +exception. + +The <tt/ThreadId/ for the current thread can be obtained with +<tt/myThreadId/: + +<tscreen><verb> +myThreadId :: IO ThreadId +</verb></tscreen> + NOTE: if you have a @ThreadId@, you essentially have a pointer to the thread itself. This means the thread itself can't be garbage collected until you drop the @ThreadId@. This misfeature will -- GitLab