本文整理汇总了C++中semaphore::release方法的典型用法代码示例。如果您正苦于以下问题:C++ semaphore::release方法的具体用法?C++ semaphore::release怎么用?C++ semaphore::release使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类semaphore
的用法示例。
在下文中一共展示了semaphore::release方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: producer_finished
/**
* Reduce working producer count by 1.
*/
void producer_finished() {
#pragma omp critical
{
producer_count -= 1;
can_read.release();
}
}
示例3: 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();
}
}
示例4: 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();
}
}
示例5: store
/**
* Store book into storage.
*/
void store(book &b) {
#pragma omp critical
{
bool saved = false;
for (vector<book>::iterator it = books.begin(); it < books.end(); it++) {
if (it->year == b.year) {
debug << "found existing book " << it->title << ", incrementing from "
<< it->count << " to " << (it->count + b.count) << " by " << b.count << "\n";
it->count += b.count;
saved = true;
}
}
if (! saved) {
debug << "adding new book " << b.title << "\n";
add_book(b);
}
can_read.release();
}
}