"Writing clean concurrent programs is hard—very hard. It is much easier to write code that executes in a single thread. It is also easy to write multithreaded code that looks fine on the surface but is broken at a deeper level. Such code works fine until the system is placed under stress." As Robert C. Martin states in Clean Code book. I recommend to read the chapter on concurrency.
Btw i think you can even use a combination of bash commands to implement this: