Is putting thread on hold optimal?

前端 未结 6 1075
礼貌的吻别
礼貌的吻别 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:30

    If it's a worker thread that has units of work given to it externally, it should definitely be using signalling objects as that will ensure it doesn't use CPU needlessly.

    If it has any of its own work to do as well, that's another matter. I wouldn't suspend the thread from another thread (what happens if there's two threads delivering work to it?) - my basic rule is that threads should control their own lifetime with suggestions from other threads. This localizes all control in the thread itself.

提交回复
热议问题