This post covers concurrency in Clojure. This is a big topic. I start by discussing threads. Then I talk about different strategies for dealing with data that is shared among different threads.
Concurrency
- Threads
- Threaded poker
- refs and threads
- Atoms
- Poker with atoms
- Thread logging with agents
- Simpler concurrency
Call to Action
Problem 1
This lab asks you to create a Clojure program that will count how many primes are in a given range. Create a thread pool and have each thread check a single number in the range. If it finds a prime it will increase a counter (which should be an atom since it is shared by all of the threads). Look at the program above on Atoms as a starting point
Comments and Feedback
You can find all of these code playbacks in my free 'book', An Animated Introduction to Clojure. I am always looking for feedback so please feel free to comment here or to send me a message. You can follow me on twitter @markm208.
Top comments (0)