-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from timthelion/master
Support for grandchild threads.
- Loading branch information
Showing
2 changed files
with
48 additions
and
5 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 | 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." | ||
|
||
|
||
>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