本文整理汇总了C++中AtomicInt::value方法的典型用法代码示例。如果您正苦于以下问题:C++ AtomicInt::value方法的具体用法?C++ AtomicInt::value怎么用?C++ AtomicInt::value使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AtomicInt
的用法示例。
在下文中一共展示了AtomicInt::value方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: autoMut
FAKE_MESSAGE *get_next_msg(void *key)
{
AutoPtr<FAKE_MESSAGE> msg;
AutoMutex autoMut(msg_mutex);
if(requests.value() < NUMBER_MSGS)
{
msg.reset(PEGASUS_NEW(FAKE_MESSAGE, dq_handle) FAKE_MESSAGE(key, 0));
/*****
check for corrupted memory
char *p = (char *)msg;
p += sizeof(FAKE_MESSAGE);
*p = 0x00;
if(peg_suballocator::CheckMemory(msg))
abort();
******/
requests++;
}
return msg.release();
}
示例2: test02
// Test Thread and AtomicInt
void test02()
{
const Uint32 numThreads = 64;
AtomicInt * atom = new AtomicInt(0);
Thread* threads[numThreads];
(*atom)++;
Boolean zero = atom->DecAndTestIfZero();
assert(zero);
for (Uint32 i=0; i<numThreads; i++)
{
threads[i] = new Thread(atomicIncrement, atom, false);
}
for (Uint32 i=0; i<numThreads; i++)
{
threads[i]->run();
}
for (Uint32 i=0; i<numThreads; i++)
{
threads[i]->join();
delete threads[i];
}
assert(atom->value() == numThreads);
delete atom;
}
示例3: main
PEGASUS_NAMESPACE_END
int main(int argc, char **argv)
{
PEGASUS_START_LEAK_CHECK();
const char* tmpDir = getenv ("PEGASUS_TMP");
if (tmpDir == NULL)
{
tmpDir = ".";
}
String traceFile (tmpDir);
traceFile.append("/dq_memory_trace");
Tracer::setTraceFile (traceFile.getCString());
Tracer::setTraceComponents("Memory");
Tracer::setTraceLevel(Tracer::LEVEL4);
AutoPtr<dq_handle>(new peg_suballocator::SUBALLOC_HANDLE());
read_write rw =
{
new AsyncDQueue<FAKE_MESSAGE>(true, 100),
new AsyncDQueue<FAKE_MESSAGE>(true, 100)
};
Thread *client_sender[20];
Thread *server[10];
int i;
FAKE_MESSAGE *test = PEGASUS_ARRAY_NEW(FAKE_MESSAGE, 10, dq_handle.get());
PEGASUS_ARRAY_DELETE(test);
for( i = 0; i < NUMBER_CLIENTS; i++)
{
client_sender[i] = new Thread(client_sending_thread, &rw, false );
client_sender[i]->run();
}
for( i = 0; i < NUMBER_SERVERS; i++)
{
server[i] = new Thread(server_thread, &rw, false);
server[i]->run();
}
while( requests.value() < NUMBER_MSGS || replies.value() < NUMBER_MSGS )
{
pegasus_sleep(1000);
}
rw.incoming->shutdown_queue();
rw.outgoing->shutdown_queue();
PEGASUS_STOP_LEAK_CHECK();
PEGASUS_CHECK_FOR_LEAKS(dq_handle.get());
for( i = 0; i < NUMBER_CLIENTS; i++)
{
client_sender[i]->join();
delete client_sender[i];
}
for( i = 0; i < NUMBER_SERVERS; i++)
{
server[i]->join();
delete server[i];
}
cout << NUMBER_MSGS << " messages using " << NUMBER_CLIENTS << " clients and " << NUMBER_SERVERS << " servers" << endl;
cout << endl << "total requests: " << requests.value() << "; total replies: " << replies.value() << endl;
cout << "unclaimed requests: " << rw.outgoing->count() << endl;
delete rw.incoming;
delete rw.outgoing;
return 0;
}