Tag Info

New answers tagged

0

There are many concurrency models so you'd better have a good idea about all before you decide which one to pick. For that, I recommend the book Seven Concurrency Models in Seven Weeks: When Threads Unravel. Check the reviews and the TOC and you can see why this is a good book. And it is also recent (2014).


0

To learn about concurrency, use a language that was designed for concurrency. Golang is a good choice since it has built-in support for concurrency and a C-like syntax which makes the language easy to learn for most programmers. It has message passing, mutexes etc which cover almost all of your concurrency needs and which have more complicated equivalents ...


3

The other answers are quite good and clearly address the correctness concerns. Let me address your more general question: How much work should I place inside a lock statement? Let's start with the standard advice, that you allude to and delnan alludes to in the final paragraph of the accepted answer: Do as little work as possible while locking a ...


32

This is not a question of performance. It is first and foremost a question of correctness. If you have two lock statements, you can not guarantee atomicity for operations that are spread between them, or partially outside the lock statement. Tailored for the old version of your code, this means: Between the end of the while (_runningWorkers >= ...


11

IMHO you are asking the wrong question - you should not care so much about efficiency trade-offs, but more about correctness. The first variant makes sure _runningWorkers is only accessed during a lock, but it misses the case where _runningWorkers might be changed by another thread in the gap between the first lock and the second. Honestly, the code looks ...


0

Don't. It's not a static class, and they aren't static methods, so there's no reason why it shouldn't be up to calling code to avoid concurrent calls. With static methods, then you would have to do some of the work to make it handle concurrent calls because calling code can't guarantee that it is the only calling code. And of course with instance methods ...


4

The more I think about this analogy the less sense it makes. Ports don't work as a resource here. A server will have only a handful of ports open, perhaps only one (say, port 80 for HTTP). Any number of clients can connect to this and their connections are differentiated by the client port ID (and client IP), which are independent for each client. Port ...



Top 50 recent answers are included