forked from bsl/threadmanager
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for grandchild threads.
- Loading branch information
1 parent
f5da12c
commit c23e19c
Showing
3 changed files
with
76 additions
and
9 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,35 @@ | |||
What happens if I create a tree of threads like: | |||
|
|||
ThreadMain | |||
ChildThread | |||
GrandChildThread | |||
|
|||
And ChildThread ends? Normally GrandChildThread dies. This module tests whether ThreadManager successfully flattens this thread hierarchy to: | |||
|
|||
ThreadMain | |||
ChildThread | |||
GrandChildThread | |||
|
|||
thus saving GrandChildThread in the case of ChildThread's death. | |||
|
|||
>import qualified Control.Concurrent.ThreadManager as TM | |||
>import Control.Concurrent | |||
|
|||
>main :: IO () | |||
>main = do | |||
> tm <- TM.make | |||
> TM.fork tm (childThread tm) | |||
> TM.waitForAll tm | |||
> print "If you see this message, your grandChild has died and you should morn like the poorest of poppers." | |||
|
|||
|
|||
>childThread :: TM.ThreadManager -> IO () | |||
>childThread tm = do | |||
> TM.fork tm (grandChildThread 0) | |||
|
|||
> return () | |||
|
|||
>grandChildThread :: Int -> IO () | |||
>grandChildThread count = | |||
> print count >> threadDelay 1000 >> (grandChildThread $ count+1) | |||
|
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