Can a thread call SuspendThread by passing its own thread id?

Can a Windows thread suspend itself using SuspendThread() ?

I can wake him from another, but can he call SuspendThread(GetCurrentThreadId()) ?

+4
source share
2 answers

This seems to be possible, but with a little change (see the cygwin mailing list discussing this one here ):

 SuspendThread(GetCurrentThread()); 

I also found that MSDN says that the thread should only pause, but this does not make me understand. I quote (from here , my hit):

This feature is primarily intended for use by debuggers. It is not intended for thread synchronization. Calling SuspendThread on a thread that owns a synchronization object, such as a mutex or critical sector, can lead to a deadlock if the calling thread tries to get a synchronization object that belongs to a suspended thread. To avoid this situation, a thread in an application that is not a debugger should signal that another thread is pausing . The target thread should be designed to follow this signal and respond accordingly.

+7
source

Yes, you can use SuspendThread for the current thread. Good to read on the topic .

+3
source

Source: https://habr.com/ru/post/1494459/


All Articles