作者:许婉玟秀贤 | 来源:互联网 | 2023-10-14 08:22
SayIhaveafunctionwork(),onceitiscalled,Idontwantittobecalledinthenext5seconds.
Say I have a function work(), once it is called, I don't want it to be called in the next 5 seconds. Currently, I have designed some simple codes as:
假设我有一个函数work(),一旦调用它,我不希望它在接下来的5秒内被调用。目前,我设计了一些简单的代码:
connect(timer,SIGNAL(timeout()),this,SLOT(resetflag()));
...
if(!flag)
{
flag = true;
work();
timer.start();
}
...
void resetflag(){
flag = flase;
}
My question is: 1.) How to make this thread safe? 2.) Is there any simpler and elegant way of doing this?
我的问题是:1。)如何使这个线程安全? 2.)有没有更简单和优雅的方式这样做?
1 个解决方案