本文整理汇总了C++中semaphore::acquire方法的典型用法代码示例。如果您正苦于以下问题:C++ semaphore::acquire方法的具体用法?C++ semaphore::acquire怎么用?C++ semaphore::acquire使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类semaphore
的用法示例。
在下文中一共展示了semaphore::acquire方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: consume
/**
* Consume a book by filter.
*
* Return number of items consumed.
*/
unsigned int consume(filter &f) {
can_read.acquire();
unsigned int consumed = 0;
#pragma omp critical
{
book *b = find_by_year(f.year);
if (b != NULL) {
unsigned int wants_to_consume = f.get_wants_to_consume();
if (b->count < wants_to_consume)
consumed = b->count;
else
consumed = wants_to_consume;
b->count -= consumed;
if (b->empty()) {
debug << "Deleting " << b->title << endl;
remove(b);
}
f.consume(consumed);
}
else {
can_read.release();
}
}
return consumed;
}
示例2: Make
void Make(int add) {
int used;
while(!doneUsing){
S.acquire();
if((howMany % 2 == 0 && howMany != used) || (howMany % 3 == 0 && howMany != used)){
common += add;
used = howMany;
}
S.release();
}
}
示例3: Use
void Use(int procNr) {
int val;
while(!doneUsing){
S.acquire();
if(howMany < 10 && val != common){
cout << procNr << ") reiksme: " << common << endl;
val = common;
howMany++;
} else if (howMany == 10) {
doneUsing = true;
}
S.release();
}
}