30
votes
A multi-threaded Producer Consumer with C++11
Prefer Reference over Pointer
Since the producer and consumer must have a buffer you should pass it by reference (rather than pointer). This also makes sure there is no confusion over ownership of ...
24
votes
AsyncDictionary - Can you break thread safety?
The reason why there is no async API for a dictionary is, that all operations on a dictionary are so fast, that there is no need for asynchronicity.
For concurrent scenarios there is the thread safe ...
21
votes
Accepted
Voxel World Optimization
To solve this problem, I made each Voxel aware of its neighbours, this was achieved in the world generation/height-map loading phase.
Then I was able to change the optimization algorithm to the ...
16
votes
A multi-threaded Producer Consumer with C++11
I have a few comments about your code:
Using std::lock_guard is great to handle mutexes since it automatically unlocks the acquired mutex when leaving the scope. ...
15
votes
Send email just once per day
Couple of remarks:
IsSent() smells like a property, not a method. It should be more descriptive as well: what object are you calling this on? It seems to indicate ...
14
votes
Accepted
Using Java 8 parallel streams
Your code is not thread-safe. Each of the threads will, in parallel, be accessing both the best, and the bestQuality variables.
...
14
votes
Accepted
Hybrid Lock Implementation
I would expect the standard library's mutex (which is basically pthread_mutex) to already take care of this optimization behind ...
13
votes
AsyncDictionary - Can you break thread safety?
Threading Design
Your implementation has a very intrusive lock for all read and write operations, using the SemaphoreSlim with max concurrency 1.
...
12
votes
Accepted
Simple Implementation of a ReentrantLock
Your code looks sensible, with two exceptions, the unlock should only notify when the lock is unlocked.... your code currently allows for asymmetrical notifications (excessive notifications).
...
12
votes
AsyncDictionary - Can you break thread safety?
It's pretty hard to break something that uses a global lock around everything. So this seems pretty thread-safe. But that doesn't answer the question of why you'd want to use this.
Asynchronous ...
11
votes
Accepted
11
votes
Accepted
Printing even and odd using two concurrent threads
public class Odd implements Runnable{
private Monitor sharedObject;
public Odd(Monitor monitor){
this.sharedObject = monitor;
}
You implemented the class as ...
11
votes
Accepted
A buffer that holds and provides the latest n items
Naming
There is one 'u' in ConcuurentCircularBuffer that wants to be a 'r' --> ConcurrentCircularBuffer
There is no need to abbreviate name like size (sz --> ...
11
votes
Accepted
Parallelized for loop in Bash
Some suggestions:
The trailing slash in the mkdir command is redundant.
$(…) is preferred over backticks for command ...
10
votes
Send email just once per day
Normally, you don't catch Exceptions to throw them again, it doesn't make sense, let them rise up, don't catch them here, I don't think it is your intention to stop the exceptions here, so don't.
...
10
votes
Accepted
Concurrent Linked Hash Set
There are several thread safety issues :
if size(), remove() and removeAll() need to ...
10
votes
A buffer that holds and provides the latest n items
In addition to @JanDotNet's answer:
You can use "less strict" lock in your code, specifically ReaderWriterLock or ...
10
votes
Accepted
RabbitMQ wrapper to work in a concurrent environment
A few things that caught my eye:
So called dispose pattern only makes sense if you implement a finalizer on your base class or on one of its descendants. If you do ...
10
votes
Accepted
A portable parallel loop construct in C89
The code for apple and linux cases is identical (except one case). Consider
#if defined(__APPLE__) || defined(__linux__)
#define POSIX
#endif
and consolidate the ...
9
votes
Accepted
Concurrent LRU cache using sychronizedMap() or ReadWriteLock
My experience with variants on the java.util.concurrent.locks.* classes suggests that their sweet spot in terms of performance is when the work to be done is ...
9
votes
Accepted
Caching Color-Bitmaps as MemoryStreams
First I'm not a fan of recycling IDs. Too much confusion can happen. For example Thread 1 adds a Dog Image and gets ID 1. Thread 2 calls ReleaseAllImages and then adds a Cat image and gets ID 1. ...
9
votes
Accepted
AsyncDictionary - Can you break thread safety?
If you modify the AsyncDictionary while enumerating its keys/values it throws InvalidOperationException (if the backing ...
8
votes
A buffer that holds and provides the latest n items
You can make your code much simpler if you use a LinkedList<T> instead of an array. It has also a much better performance when inserting and removing items in ...
7
votes
Using Java 8 parallel streams
http://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html#max-java.util.Comparator-
Returns the maximum element of this stream according to the provided Comparator. This is a special ...
7
votes
Send email just once per day
you should be using a couple of using statements in your code, then you can get rid of the try/finally statement completely because the closing/disposing of the ...
7
votes
Parallel "wget" in Java
Just a rant, someone else will do the real work, but for me it's hard to read.
durl = url;
When I see it..... what to say?
So slowly... "url" is fine, everybody ...
7
votes
Threadsafe HashMap with snapshot support
There are a number of things that I think you have completely overengineered.
Holder
This can be replaced with Optional
SingleSnapshotMap
This class exposes 4 ...
7
votes
Accepted
Solving a race condition
Concurrency Strategy
In general, using volatile is complicated, partially because the meaning of volatile changed in Java 1.4, ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
concurrency × 446java × 175
multithreading × 125
go × 67
c# × 62
thread-safety × 58
c++ × 54
performance × 37
queue × 27
locking × 23
python × 20
asynchronous × 19
producer-consumer × 19
beginner × 17
cache × 17
c++11 × 16
async-await × 14
http × 13
c × 12
atomic × 12
task-parallel-library × 11
.net × 10
javascript × 9
algorithm × 9
lock-free × 9