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 ...
user avatar
  • 91.7k
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 ...
user avatar
  • 8,498
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 ...
user avatar
  • 376
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. ...
user avatar
  • 19.9k
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 ...
user avatar
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. ...
user avatar
  • 96.7k
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 ...
user avatar
  • 19.1k
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. ...
user avatar
  • 13.8k
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). ...
user avatar
  • 96.7k
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 ...
user avatar
  • 525
11 votes
Accepted

Readers-writers problem using wait notify

This code in the read() method is broken: ...
user avatar
  • 96.7k
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 ...
user avatar
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 --> ...
user avatar
  • 8,498
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 ...
user avatar
  • 8,737
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. ...
user avatar
  • 28.5k
10 votes
Accepted

Concurrent Linked Hash Set

There are several thread safety issues : if size(), remove() and removeAll() need to ...
user avatar
  • 5,359
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 ...
user avatar
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 ...
user avatar
  • 13k
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 ...
user avatar
  • 53.4k
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 ...
user avatar
  • 96.7k
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. ...
user avatar
  • 4,096
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 ...
user avatar
  • 2,864
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 ...
user avatar
  • 43.8k
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 ...
user avatar
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 ...
user avatar
  • 28.5k
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 ...
user avatar
  • 13.4k
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 ...
user avatar
  • 96.7k
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, ...
user avatar
  • 96.7k

Only top scored, non community-wiki answers of a minimum length are eligible