Any serious flaws in this approach? Not sure if the overhead resume / pause the stream?
Yes , resuming / pausing a thread is a very dangerous job done in user mode of the program . Therefore, it should not be used (almost never). Moreover, we should not use these concepts to achieve what any modern planner does for us. This is also mentioned in another article of this question.
The above applies to any operating system, but from the SO post tag it seems to me that he was offered the Microsoft Windows system . Now, if we read about SuspendThread () from MSDN, we get the following:
"This function is primarily intended for use by debuggers. It is not intended to synchronize threads. Calling SuspendThread on a thread that owns a synchronization object, such as a mutex or critical section, can lead to a deadlock if the calling thread tries to get a synchronization object that belongs to a suspended thread." .
So, consider a scenario in which a thread has acquired some resource (implicitly. Part of the code ... in library or kernel mode), and if we pause the thread, this will lead to a mysterious deadlock situation, as other threads of this process will wait for this particular resource. The fact is that we are not sure (at any time) in our program that what resources will be received by any running thread, pausing / resuming a thread is not a good idea.
source share