Skip to main content
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 ...
JanDotNet's user avatar
  • 8,598
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. ...
dfhwze's user avatar
  • 14.2k
12 votes
Accepted

Parallelized for loop in Bash

Some suggestions: The trailing slash in the mkdir command is redundant. $(…) is preferred over backticks for command ...
l0b0's user avatar
  • 9,117
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 ...
Voo's user avatar
  • 525
12 votes
Accepted

Reduce String Length With Thread Safety & Concurrency

Your class is not really a URL shortener. It is a component in a URL shortener that creates a hash code for a URL. Thus the name of the class should be changed to something like ...
TorbenPutkonen's user avatar
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 ...
vnp's user avatar
  • 58.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. ...
CharlesNRice's user avatar
  • 4,438
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 ...
Johnbot's user avatar
  • 3,084
9 votes
Accepted

Multi Threaded High Performance txt file parsing

I hope you don't mind a pure C solution. For me it is easier to optimize code without C++ abstractions. But it should be straightforward to convert it to idiomatic C++ code. ...
Gaslight Deceive Subvert's user avatar
8 votes

Single Producer Single Consumer lockless ring buffer implementation

Performance is better with volatile because its unsafe as it doesn't generate a memory barrier and thus has a data race and should not be used in at multi threaded context. As such the code is broken ...
Emily L.'s user avatar
  • 16.7k
8 votes
Accepted

Debounce and throttle tasks using Swift Concurrency

The problem is the use of a nonisolated function to initiate an asynchronous update of an actor-isolated property. (I'm surprised the compiler even permits that.) ...
Rob's user avatar
  • 2,657
8 votes

Yet another shared_ptr implementation for learning purposes

Much of the same feedback I’ve given on other shared_ptr implementations applies here. In particular: This design of ...
Davislor's user avatar
  • 9,115
8 votes

Yet another shared_ptr implementation for learning purposes

Critical Bugs Bug 1 explicit shared_ptr(std::unique_ptr<T>&& ptr) : control_(new control_block(ptr.get())) { } This is broken. ...
Loki Astari's user avatar
  • 97.7k
8 votes

A thread-safe performant URL Shortener in Java

Thread-safety of addUrl() Method computeIfAbsent() is guaranteed to be executed as an atomic action when invoked on a ...
Alexander Ivanchenko's user avatar
8 votes

Reduce String Length With Thread Safety & Concurrency

replaceFirst doesn't guarantee that whatever it replaces is actually at the start of the input string. This may be a problem for an input like ...
Sara J's user avatar
  • 4,221
7 votes

Yet another shared_ptr implementation for learning purposes

Make sure your operations are really atomic Using atomic variables does not automatically make the operations on your objects atomic. Consider these lines in ...
G. Sliepen's user avatar
  • 69.3k
7 votes
Accepted

Multithreaded array summation in Java - best practice, structure, acceptable use of Constant classes. There is no concurrency?

SRP There is a school of thought out there that writing an utility class is indicative of a design smell. While I don't always agree, particularely with small pet projects like this, ...
Jannik S.'s user avatar
  • 526
6 votes

TaskScheduler that uses a dedicated thread

Dispose the scheduler gracefully As you mentioned, you lack proper disposal functionality. ...
dfhwze's user avatar
  • 14.2k
6 votes
Accepted

A "zero copy" concurrent queue in C++ that supports exactly two threads; one for pushing and one for popping

As to question 1: Yes, what you are doing is unsafe. Yes, there are better alternatives. Why is allocating memory manually unsafe? The most simple reason is: You might forget to free it (in which ...
Ben Steffan's user avatar
  • 5,333
6 votes
Accepted

ReadWriteSerializer

Spinlocks should only be held for a very short time Spinlocks are expensive; they cause a thread that tries to take a lock to use 100% CPU time. So when you have the lock, you should release it as ...
G. Sliepen's user avatar
  • 69.3k
6 votes
Accepted

ForEachAsync extension method (a way to run an async operation on each item of a sequence in parallel)

Rather than writing something custom, you could use the TLP Dataflow library. ...
Matt Cole's user avatar
  • 968
6 votes

Caching Color-Bitmaps as MemoryStreams

Spell-check: ReleaseIamge should presumably be ReleaseImage; uique should be ...
Peter Taylor's user avatar
  • 24.5k
6 votes

Caching Color-Bitmaps as MemoryStreams

I wrote this a few hours; hopefully I've removed everything that was overlapping too much with the other answers Add(Bitmap bitmap) I also really don't like this, ...
VisualMelon's user avatar
  • 7,591
6 votes

Go grep command clone

The thing is, even so, standard grep still gets results faster by an amount of 60 % less processing time For more information on what makes GNU grep fast, read this by the original author. Here is ...
esote's user avatar
  • 3,800
6 votes

Golang execute several go routine in loop and then wait

Every time you execute a go statement it is passed to the scheduler. What if scheduling is delayed? wg.Add(1) is not executed ...
peterSO's user avatar
  • 3,591
6 votes

Upload a directory, in parallel, to an artifact repository

I think you'll find that inotify has problems of its own and that you're already on the right path. The approach I'd use: get this working the way you want, then run it in a loop while your wget ...
Oh My Goodness's user avatar
6 votes

Determine concurrent access to a function

A few observations off the top of my head cerrMutex is unused, and should be removed if not needed. mapMutex is used to guard ...
Josiah's user avatar
  • 6,106
6 votes

A multi-thread Producer Consumer, where a Consumer has multiple Producers (C++17)

I get a couple of warnings, which ought to be fixed: ...
Toby Speight's user avatar
  • 88.3k
6 votes
Accepted

Banking application - Optimizing java multi-threading code

This code is broken. Imagine an Account with $100, two threads, one depositing $1, the other withdrawing $50. Thread one acquired ...
AJNeufeld's user avatar
  • 35.3k

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