6
$\begingroup$

I am self-learning concurrent programming. I have some experience with concurrent programming. Have self learned OS and programming.

There are both programming languages and libraries that provide concurrent programming facilities. I would like to learn about concurrent programming at OS and library levels (e.g. multithreading, multiprocessing, spin locks, semaphore, ...) and language level (e.g. monitor, future, promise, channels, conditional critical regions, Coroutine, ...). For the specific topics, I am referring to sections "Models", "Prevalence" and "Languages supporting concurrent programming" in https://en.wikipedia.org/wiki/Concurrent_computing and also concurrency patterns.

I would like to learn at conceptual as well as specific language levels.

  • Could you recommend some books which explain the different approaches at a concept level? It is good for such books to have specific languages and libraries as examples, but not necessarily especially if the books you recommend are classic but not contemporary.

  • Could you also recommend which specific languages and libraries and books on specific languages and libraries? For specific languages, I am currently interested in functional languages (such as Scala, Haskell, OCaml ...), Python, C#, Java, C/C++ and Go.

Academic books (text books, survey) and professional/practical books are both welcome.

$\endgroup$
2
  • $\begingroup$ @Buffy: I value concepts as much as technical details in specific languages, because that will help me learn concurrent programming knowledge that can apply to all/most languages, without being lost in the differences between specific langauges. I am not sure if searches in specific languages will help me achieve that goal. $\endgroup$
    – Tim
    Commented Sep 17, 2017 at 12:50
  • $\begingroup$ My first book ever on this subject was "Concurrent C" - this is not a book about actual C, it suggests an extension to C, which would implement communicating-processes calculus. This book seems to have inspired Go authors, and, perhaps Erlang authors (not sure which came first, the book or the language). Clojure has implementation of CSP, though due to the difference in syntax the similarities aren't immediately apparent. $\endgroup$
    – wvxvw
    Commented Oct 1, 2017 at 11:29

5 Answers 5

4
$\begingroup$

Concurrent programming is easy, synchronisation is hard.

Have a look at this video for an alternative to synchronisation: https://www.youtube.com/watch?v=2yXtZ8x7TXw

When you have to synchronize

Use easy (High level) synchronization. see:

  • Scoop from Eiffel.
  • Transactions
  • Pipelines / message passing
  • coroutines (for when you don't need parallelisation)

See also no lock / zero lock structures: Most pipes that are thread safe use locking. Or are not thread safe, and expect the user to do the locking. However it is possible to get thread safe zero lock queues. There rely on a few atomic instructions. (I prefer the name minimal lock, because the atomic instructions do locking).

Only use low-level synchronization to implement high-level synchronisation.

If you need synchronisation, and if you do not have high-level synchronisation, then find a good library that implements high-level synchronisation, using the existing low-level synchronisation.

Don't write it your self, except as an exercise (and do to it as an exercise, it is fun and you will learn a lot), as it is very hard and you will get it wrong.

$\endgroup$
3
$\begingroup$

Since the OP asked about functional programming, so I would highly recommend you to read "Learning Concurrent Programming in Scala" by Aleksandar Prokopec, (2014). All the examples for this book are available on GitHub to give you some idea of the book before you purchase it.

C#

I would recommend you to read "Professional Parallel Programming with C#" - its based on .Net 4.0 and I have no update about following editions (if any)

C++

I think Pacheco's book would be my recommendation for sure

Best of luck!

$\endgroup$
2
$\begingroup$

I have no recommendations for the theory part but since you are asking for implementation advice as well, here we go.

If you are looking to use C sharp (you haven't specified a specific language of choice) then, as a dot net guy myself, I would recommend you start your self learning on concurrent programming with .NET implementation of same at Threads and Threading.

The link provides with what you can (most of the things you have discussed can be done in C sharp Threads) and what you cannot do.

If you wish to dig deep, there are no specific books on threads in C sharp, but you can use the reference book I used which contains detailed implementation notes on the same at C sharp 70 483

$\endgroup$
2
  • $\begingroup$ Thanks. Can you tell more about "I am doing something similar but with functional programming"? By "functional programming", do you mean some other languages than C#? $\endgroup$
    – Tim
    Commented Sep 17, 2017 at 12:09
  • $\begingroup$ I do a lot of self learning too and most recently (since 3 days or so) I have started self learning functional programming and asking questions about books and stuff. $\endgroup$
    – Jay
    Commented Sep 17, 2017 at 13:03
2
$\begingroup$

The Well Grounded Java Developer has an excellent section on concurrency. The author claims that very few developers correctly implement concurrency. As ctrl-alt-delor put it: concurrency is easy; synchronization is hard.

In fact, avoiding errors from race conditions and unexpected asynchronous behavior is so difficult that the author recommends developers always use one of the Java 7 library features to implement multi-tasking.

I have personally found debugging asynchronous code to be very hard. Errors just seem intractable and difficult to reproduce. While the libraries used in the book are Java specific, the reasons for needing those libraries are not.

$\endgroup$
2
$\begingroup$

One book I have enjoyed is The Little Book of Semaphores by A. Downey. It is free (in both senses of the word) and contains many problems with hints and solutions that can be used as starting points for small group projects (e.g., to implement such a solution in a modelling tool or to generalise it).

I have only used the conceptual chapters, but the book also contains chapters on synchronisation in Python and C.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.