HACKER Q&A
📣 mettamage

How to learn multithreaded / concurrent / multiprocessor programming?


During my work as a full-stack software engineer I'm not learning anything about multithreaded programming. The best programmers I know that work at companies that do technically challenging things know the topic of multithreaded data structures and algorithms pretty well, by intuition.

At university, I followed a course based on the book of Maurice Herlihy [1], the videos are locked. At the time, I barely passed the course because of doing too many courses. So I want to relearn the topic, properly this time.

So I wondered: according to you, what is the best way of learning multithreaded programming?

[1] He also teaches a course, the slides are here somewhere: http://cs.brown.edu/courses/cs176/course_information.shtml


  👤 skinner927 Accepted Answer ✓
The best way to learn anything is to do it, fail, learn from it, and do it again. You’ll never achieve perfection, but each iteration should get better.

Do something simple. Create a terminal weather app. Separate the “client” and “backend” into separate processes simply for the complexity of it.

Have the client end process commands, send requests to the backend, and render results.

The backend should receive commands from the client app and send back responses.

I’d suggest staying away from HTTP and try to use a pipe between the two processes and come up with your own protocol.

Bonus points if you make the api non-blocking and the client has to query the backend for results.

Add artificial delays. Add artificial failures. Add logging. Switch to protobufs. Create a distributed backend. Send messages over a queueing/task system instead of a bare pipe. Dockerize it. Simulate hundreds of clients. Go nuts.

Taking a silly simple application and making it overly complex is a good way to learn because you’re not burdened by the complexity of the problem, but instead the burden is on the thing you’re tying to learn.

Practice practice practice.