Is putting thread on hold optimal?

前端 未结 6 1068
礼貌的吻别
礼貌的吻别 2021-01-05 01:11

Application has an auxiliary thread. This thread is not meant to run all the time, but main process can call it very often.

So, my question is, what is more optimal

6条回答
  •  一生所求
    2021-01-05 01:26

    I would assume Andrei doesn't use Delphi to write .NET and therefore Suspend doesn't translate to System.Threading.Thread.Suspend but to SuspendThread Win32 API.

    I would strongly suggest against it. If you suspend the thread in an arbitrary moment, then you don't know what's going to happen (for example, you may suspend the thread in such a state the some shared resource is blocked). If you however already know that the thread is in suspendable state, then simply use WaitForSingleObject (or any other WaitFor call) - it will be equally effective as suspending the thread, i.e. thread will use zero CPU time until it is awaken.

提交回复
热议问题