本文整理汇总了C++中Obj::post方法的典型用法代码示例。如果您正苦于以下问题:C++ Obj::post方法的具体用法?C++ Obj::post怎么用?C++ Obj::post使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Obj
的用法示例。
在下文中一共展示了Obj::post方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pushInt
void IntQueue::pushInt(int n)
{
d_mutexSem.wait();
d_queue.push_front(n);
d_mutexSem.post();
d_resourceSem.post();
}
示例2: getInt
int IntQueue::getInt()
{
// Waiting for resources.
d_resourceSem.wait();
// 'd_mutexSem' is used for exclusive access.
d_mutexSem.wait();
int ret = d_queue.back();
d_queue.pop_back();
d_mutexSem.post();
return ret;
}
示例3: main
int main(int argc, char *argv[]) {
int test = argc > 1 ? atoi(argv[1]) : 0;
int verbose = argc > 2;
cout << "TEST " << __FILE__ << " CASE " << test << endl;
switch (test) { case 0: // Zero is always the leading case.
case 6: {
///Usage
///-----
// This component is an implementation detail of 'bslmt' and is *not* intended
// for direct client use. It is subject to change without notice. As such, a
// usage example is not provided.
// USAGE EXAMPLE
IntQueue testQueue;
testQueue.pushInt(1);
ASSERT(1 == testQueue.getInt());
testQueue.pushInt(2);
ASSERT(2 == testQueue.getInt());
} break;
case 5: {
// --------------------------------------------------------------------
// TESTING 'tryWait'
//
// Concerns:
// 1. 'tryWait' decrements the count if resources are available,
// or return an error otherwise.
//
// Plan:
// We create two groups of threads. One will call 'post', the other
// 'tryWait'. First, we make sure that 'tryWait' fails if no
// resources are available. Then we will make sure it succeeds if
// resources are. We will also test 'tryWait' in the steady state
// works fine.
//
// Testing:
// void tryWait();
// --------------------------------------------------------------------
if (verbose) cout << endl
<< "Testing 'trywait'" << endl
<< "=================" << endl;
bslmt::ThreadUtil::Handle threads[10];
MyBarrier barrier(10);
Obj sem;
struct ThreadInfo5 info;
info.d_numIterations = 5000; // number of ops per thread / 3
info.d_barrier = &barrier;
info.d_sem = &sem;
for (int i = 0; i < 5; ++i) {
ASSERT(0 == bslmt::ThreadUtil::create(&threads[i * 2],
thread5Post,
&info));
ASSERT(0 == bslmt::ThreadUtil::create(&threads[i * 2 + 1],
thread5Wait,
&info));
}
for (int i = 0; i < 10; ++i) {
ASSERT(0 == bslmt::ThreadUtil::join(threads[i]));
}
} break;
case 4: {
// --------------------------------------------------------------------
// TESTING 'post(int)'
//
// Concerns:
// 1. post(int) increments the count by the expected number
//
// Plan:
// Create a set of threads calling 'wait' and use a thread to post a
// number smaller than the set of threads.
//
// Testing:
// void post(int number);
// --------------------------------------------------------------------
if (verbose) cout << endl
<< "Testing 'post(int number)'" << endl
<< "==========================" << endl;
bslmt::ThreadUtil::Handle threads[6];
MyBarrier barrier(6);
Obj sem;
struct ThreadInfo4 info;
info.d_numIterations = 10000; // number of ops per thread
info.d_numWaitThreads = 5;
info.d_barrier = &barrier;
info.d_sem = &sem;
for (int i = 0; i < 5; ++i) {
//.........这里部分代码省略.........