Initial Commit - Lesson 31 (Commit #1)
This commit is contained in:
37
Plugins/GameLiftServerSDK/ThirdParty/concurrentqueue/tests/CDSChecker/enqueue_dequeue_one.cpp
vendored
Normal file
37
Plugins/GameLiftServerSDK/ThirdParty/concurrentqueue/tests/CDSChecker/enqueue_dequeue_one.cpp
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
// ©2013 Cameron Desrochers.
|
||||
// Distributed under the simplified BSD license (see the LICENSE file that
|
||||
// should have come with this file).
|
||||
|
||||
#include "model-checker/include/threads.h"
|
||||
#include "corealgo.h"
|
||||
|
||||
void producer_thread(void*)
|
||||
{
|
||||
enqueue(1234);
|
||||
}
|
||||
|
||||
void consumer_thread(void*)
|
||||
{
|
||||
int element;
|
||||
bool result = try_dequeue(element);
|
||||
MODEL_ASSERT(!result || element == 1234);
|
||||
|
||||
if (result) {
|
||||
MODEL_ASSERT(!try_dequeue(element));
|
||||
}
|
||||
}
|
||||
|
||||
int user_main(int, char**)
|
||||
{
|
||||
init();
|
||||
|
||||
thrd_t p, c;
|
||||
|
||||
thrd_create(&p, &producer_thread, nullptr);
|
||||
thrd_create(&c, &consumer_thread, nullptr);
|
||||
|
||||
thrd_join(p);
|
||||
thrd_join(c);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user