Exit a method if another thread is executing it

后端 未结 4 2144
既然无缘
既然无缘 2021-02-07 13:18

I have a method in a multi-threaded application and I\'d like the following behavior when this method is invoked:

  1. If no other threads are currently executing the m
4条回答
  •  青春惊慌失措
    2021-02-07 14:09

    create bool variable somewhere else, set on true when start method and to false on exit from method, before run method check if variable is false then run else exit from method

提交回复
热议问题