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 ...
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
Parallelized for loop in Bash
Some suggestions:
The trailing slash in the mkdir command is redundant.
$(…) is preferred over backticks for command ...
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 ...
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 ...
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
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 ...
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.
...
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 ...
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.) ...
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 ...
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. ...
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 ...
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 ...
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 ...
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, ...
6
votes
TaskScheduler that uses a dedicated thread
Dispose the scheduler gracefully
As you mentioned, you lack proper disposal functionality.
...
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 ...
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 ...
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.
...
6
votes
Caching Color-Bitmaps as MemoryStreams
Spell-check: ReleaseIamge should presumably be ReleaseImage; uique should be ...
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, ...
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 ...
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 ...
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 ...
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 ...
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:
...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
concurrency × 463java × 176
multithreading × 137
go × 69
c++ × 66
c# × 62
thread-safety × 58
performance × 41
queue × 28
locking × 25
producer-consumer × 22
python × 20
asynchronous × 20
beginner × 18
c++11 × 16
cache × 16
http × 14
async-await × 14
atomic × 13
c × 12
algorithm × 11
task-parallel-library × 11
lock-free × 11
.net × 10
rust × 9