本文整理汇总了C++中semaphore::post方法的典型用法代码示例。如果您正苦于以下问题:C++ semaphore::post方法的具体用法?C++ semaphore::post怎么用?C++ semaphore::post使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类semaphore
的用法示例。
在下文中一共展示了semaphore::post方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: consume
void task1() // producer task
{
unsigned int data_token = 0;
while(true) {
cout << "\ttask 1 " << " starts some computation at t=" << sc_time_stamp() << endl;
consume(t_prod);
cout << "\ttask 1 " << " dumps data on the circular buffer at t=" << sc_time_stamp() << endl;
#ifdef _USING_SEMAPHORE_FOR_PROTECTING_THE_ACCESS
write_sem.wait();
#endif
unprotected_cbuff.push(data_token);
#ifdef _USING_SEMAPHORE_FOR_PROTECTING_THE_ACCESS
read_sem.post();
#endif
data_token++;
#ifdef _USING_FLAG_FOR_PROTECTING_THE_ACCESS
flag1.set();
#endif
}
}
示例2:
void task2() // consumer task
{
while(true) {
cout << "Task 2 waits for data at time " << sc_time_stamp() << endl;
#ifdef _USING_FLAG_FOR_PROTECTING_THE_ACCESS
wait(flag1);
#endif
#ifdef _USING_SEMAPHORE_FOR_PROTECTING_THE_ACCESS
read_sem.wait();
#endif
// KisTA model
cout << "task 2 " << "READ " << unprotected_cbuff.pop() << " from circular buffer at t=" << sc_time_stamp() << endl;
consume(t_cons);
cout << "task 2 " << "ends some processing at t=" << sc_time_stamp() << endl;
#ifdef _USING_SEMAPHORE_FOR_PROTECTING_THE_ACCESS
write_sem.post();
#endif
}
}
示例3: run
void run(semaphore & sync_sem)
{
running.store(true, boost::memory_order_relaxed);
sync_sem.post();
perform();
}