How to test concurrency?

what are best practices and tools to test concurrency and ensure thread safe code? how do you go about testing concurrency? along with stress testing and doing static code analysis what should you check? how do you check liveness and make sure you don't get livelock, deadlock nor race conditions?
4 Replies
Sturlen
Sturlen5mo ago
depends heavily on the language. go has a built in data race detector: https://go.dev/doc/articles/race_detector
ODeadPool
ODeadPool5mo ago
that is interesting. didn't know that. what about javascript/typescript/node and java?
Sturlen
Sturlen5mo ago
not sure. go is the only one I know of
Yoers
Yoers5mo ago
Note to start: concurrency != parallelism. It's parallelism where you need to worry about shared memory access causing issues. Running code concurrenly does not mean parallel code execution will occur. Javascript is single threaded with its concurrency model being based on the event loop (which provides great performance without the need for additional threads, mostly). You don't need race detectors as it's not possible for code to run in parallel, meaning no shared memory access, which potentially causes isues such as with Golang go-routines. Look into the event loop to understand how node works, and understand its *concurrency * (AKA out of order code execution) model.