Is putting thread on hold optimal?

前端 未结 6 1123
礼貌的吻别
礼貌的吻别 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条回答
  •  梦毁少年i
    2021-01-05 01:32

    Another option would be the TMonitor introduced in Delphi 2009, which has functions like Wait, Pulse and PulseAll to keep threads inactive when there is nothing to do for them, and notify them as soon as they should continue with their work. It is loosely modeled after the object locks in Java. Like there, Delphi object now have a "lock" field which can be used for thread synchrinozation.

    A blog which gives an example for a threaded queue class can be found at http://delphihaven.wordpress.com/2011/05/04/using-tmonitor-1/

    Unfortunately there was a bug in the TMonitor implementation, which seems to be fixed in XE2

提交回复
热议问题