本文整理汇总了C++中std::condition_variable_any类的典型用法代码示例。如果您正苦于以下问题:C++ condition_variable_any类的具体用法?C++ condition_variable_any怎么用?C++ condition_variable_any使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了condition_variable_any类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: f
void f()
{
typedef std::chrono::system_clock Clock;
typedef std::chrono::milliseconds milliseconds;
L1 lk(m0);
assert(test2 == 0);
test1 = 1;
cv.notify_one();
Clock::time_point t0 = Clock::now();
while (test2 == 0 &&
cv.wait_for(lk, milliseconds(250)) == std::cv_status::no_timeout)
;
Clock::time_point t1 = Clock::now();
if (runs == 0)
{
assert(t1 - t0 < milliseconds(250));
assert(test2 != 0);
}
else
{
assert(t1 - t0 - milliseconds(250) < milliseconds(5));
assert(test2 == 0);
}
++runs;
}
示例2: main
int main()
{
{
L1 lk(m0);
std::thread t(f);
assert(test1 == 0);
while (test1 == 0)
cv.wait(lk);
assert(test1 != 0);
test2 = 1;
lk.unlock();
cv.notify_one();
t.join();
}
test1 = 0;
test2 = 0;
{
L1 lk(m0);
std::thread t(f);
assert(test1 == 0);
while (test1 == 0)
cv.wait(lk);
assert(test1 != 0);
lk.unlock();
t.join();
}
}
示例3: f
void f()
{
L1 lk(m0);
assert(test2 == 0);
test1 = 1;
cv.notify_one();
cv.wait(lk, Pred(test2));
assert(test2 != 0);
}
示例4: unlock
void unlock() {
if ( --counter == 0 ) {
cv.notify_all();
} else {
std::unique_lock<sync_object_type> barrier_lock(sync);
while(counter != 0)
cv.wait_for(barrier_lock, std::chrono::milliseconds(1));
}
}
示例5: unlock_write
//---------------------------------------------------------------------------
// function : unlock_write
/// @brief this function unlock the write operation
//---------------------------------------------------------------------------
void unlock_write( void)
{ //-------------------------- begin --------------------
std::unique_lock <spinlock> UL ( spl);
assert ( tid == this_id() and nwrite > 0) ;
nwrite -- ;
if ( nwrite == 0 )
{ cv_write.notify_all() ;
cv_read.notify_all() ;
};
};
示例6: signals
void signals()
{
std::this_thread::sleep_for(std::chrono::milliseconds(120));
std::cerr << "Notifying...\n";
cv.notify_all();
std::this_thread::sleep_for(std::chrono::milliseconds(100));
i = 1;
std::cerr << "Notifying again...\n";
cv.notify_all();
}
示例7: insert
void insert(T t) {
std::unique_lock<M> lock{mutex};
producers.wait(lock, [this]() { return begin != (end + 1) % SIZE; });
buffer[end] = t;
end = (end + 1) % SIZE;
consumers.notify_all();
}
示例8: extract
T extract() {
std::unique_lock<M> lock{mutex};
consumers.wait(lock, [this]() { return begin != end; });
T t = buffer[begin];
begin = (begin + 1) % SIZE;
producers.notify_all();
return t;
}
示例9: _process
void _process(int id) {
std::unique_lock<std::mutex> lock(io_datas[id]->mtx);
if(io_datas[id]->empty()) {
io_datas[id]->cond.wait(lock);
/* In case that the queue is not used at the begining and it shall
* make dequeue operation failed. */
if(io_datas[id]->empty()) {
lock.unlock();
return;
}
}
IoRef io = io_datas[id]->dequeue();
lock.unlock();
auto time_beg = std::chrono::steady_clock::now();
handle_io(io->offset, io->c);
auto time_end = std::chrono::steady_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(time_end - time_beg).count();
io_counter_per_thread[id]++;
perf.consumed_time += duration;
perf.io_finished++;
prod_cond.notify_one();
}
示例10: on_open
// 接続時に呼び出されるイベントリスナ
void on_open() {
std::cout << "接続しました。" << std::endl;
std::unique_lock<std::mutex> lock(sio_mutex);
is_connected = true;
// 接続処理が終わったのち、待っているメインスレッドを起こす
sio_cond.notify_all();
}
示例11: waits
void waits()
{
std::unique_lock<std::mutex> lk(cv_m);
std::cout << "Waiting... \n";
cv.wait(lk, []{return i == 1;});
std::cout << "...finished waiting. i == 1\n";
}
示例12: post
void post()
{
std::lock_guard<std::mutex> lock(mutex_);
//++count_;
work_waiting = true;
condition_.notify_one();
}
示例13: process
/*处理函数*/
void ThreadPool::process()
{
while(running)
{
try{
threadMtx.lock();
cond_var.wait(threadMtx);
threadMtx.unlock();
Message message=msgQueue.pop(); //从消息队列获得消息
int socket=message.getFd();
//获取消息长度
uint32 size=0;
Recv(socket,&size,sizeof(size),0);
//获取消息内容
char *buffer=new char[size];
Recv(socket,buffer,size,MSG_WAITALL);
//设置消息内容
message.setContent(buffer,size);
delete[] buffer;
parse(message); //交给parse解析
rmWork();
}
catch(Exception &error)
{
error.exit();
}
}
}
示例14: unlock_read
//---------------------------------------------------------------------------
// function : unlock_read
/// @brief This function unlock the read operation
//---------------------------------------------------------------------------
void unlock_read ( void)
{ //-------------------------- begin --------------------
std::unique_lock <spinlock> UL ( spl);
assert ( nread > 0 );
nread--;
if ( nread == 0 ) cv_no_readers.notify_all() ;
};
示例15: on_connected
void on_connected()
{
_lock.lock();
_cond.notify_all();
connect_finish = true;
_lock.unlock();
}