| Start |
|---|
Spawning Threads with forkIO Haskell supports many forms of concurrency and the most obvious being forking a thread using The function We can demonstrate this quite succinctly using Both actions will run in the background, and the second is almost guaranteed to finish before the last! |
Communicating between Threads with MVar It is very easy to pass information between threads using the
Let's sum the numbers from 1 to 100 million in a thread and wait on the result: A more complex demonstration might be to take user input and sum in the background while waiting for more input: As stated earlier, if you call Take the following function: We run the the two functions with some What could happen is that:
Now Thread 1 cannot read |
| Atomic Blocks with Software Transactional Memory Another powerful & mature concurrency tool in Haskell is Software Transactional Memory, which allows for multiple threads to write to a single variable of type
|
Read Article
https://develop.horje.com/learn/1434/reference