本文整理汇总了C++中InitializeConditionVariable函数的典型用法代码示例。如果您正苦于以下问题:C++ InitializeConditionVariable函数的具体用法?C++ InitializeConditionVariable怎么用?C++ InitializeConditionVariable使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了InitializeConditionVariable函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(void)
{
InitializeConditionVariable(&BufferNotEmpty);
InitializeConditionVariable(&BufferNotFull);
InitializeCriticalSection(&BufferLock);
DWORD id;
HANDLE hProducer1 = CreateThread(NULL, 0, ProducerThreadProc, (PVOID)1, 0, &id);
HANDLE hConsumer1 = CreateThread(NULL, 0, ConsumerThreadProc, (PVOID)1, 0, &id);
HANDLE hConsumer2 = CreateThread(NULL, 0, ConsumerThreadProc, (PVOID)2, 0, &id);
puts("Press enter to stop...");
getchar();
EnterCriticalSection(&BufferLock);
StopRequested = TRUE;
LeaveCriticalSection(&BufferLock);
WakeAllConditionVariable(&BufferNotFull);
WakeAllConditionVariable(&BufferNotEmpty);
WaitForSingleObject(hProducer1, INFINITE);
WaitForSingleObject(hConsumer1, INFINITE);
WaitForSingleObject(hConsumer2, INFINITE);
printf("TotalItemsProduced: %u, TotalItemsConsumed: %u\r\n", TotalItemsProduced, TotalItemsConsumed);
CloseHandle(hProducer1);
CloseHandle(hConsumer1);
CloseHandle(hConsumer2);
system("pause");
return 0;
}
示例2: Dlg_OnInitDialog
BOOL Dlg_OnInitDialog(HWND hWnd, HWND hWndFocus, LPARAM lParam) {
chSETDLGICONS(hWnd, IDI_QUEUE);
g_hWnd = hWnd; // Used by client/server threads to show status
// Prepare the SRWLock to be used
InitializeSRWLock(&g_srwLock);
// Prepare the condition variables to be used
InitializeConditionVariable(&g_cvReadyToConsume);
InitializeConditionVariable(&g_cvReadyToProduce);
// Will be set to TRUE in order to end threads
g_fShutdown = FALSE;
// Create the writer threads
DWORD dwThreadID;
for (int x = 0; x < 4; x++)
g_hThreads[g_nNumThreads++] =
chBEGINTHREADEX(NULL, 0, WriterThread, (PVOID) (INT_PTR) x,
0, &dwThreadID);
// Create the reader threads
for (int x = 0; x < 2; x++)
g_hThreads[g_nNumThreads++] =
chBEGINTHREADEX(NULL, 0, ReaderThread, (PVOID) (INT_PTR) x,
0, &dwThreadID);
return(TRUE);
}
示例3: QueueInitialize
DWORD QueueInitialize (QUEUE_OBJECT *q, DWORD msize, DWORD nmsgs)
{
/* Initialize queue, including its mutex and events */
/* Allocate storage for all messages. */
if ((q->msgArray = calloc (nmsgs, msize)) == NULL) return 1;
q->qFirst = q->qLast = 0;
q->qSize = nmsgs;
InitializeSRWLock(&q->qGuard);
InitializeConditionVariable(&q->qNe);
InitializeConditionVariable(&q->qNf);
return 0; /* No error */
}
示例4: InitializeConditionVariable
Error Cond::create(Cond **returnValue)
{
Cond *cond = new Cond;
InitializeConditionVariable(&cond->mNativeCond);
*returnValue = cond;
return Error(0);
}
示例5: _nThreads
// Constructor
drwnThreadPool::drwnThreadPool(const unsigned size) :
_nThreads(0), _threads(NULL), _args(NULL)
{
#ifdef DRWN_USE_PTHREADS
_nThreads = (size > MAX_THREADS) ? MAX_THREADS : size;
if (_nThreads > 0) {
_threads = new pthread_t[_nThreads];
_args = new drwnThreadArgs[_nThreads];
}
pthread_mutex_init(&_mutex, NULL);
pthread_cond_init(&_cond, NULL);
_bQuit = true;
_bProfilerEnabled = drwnCodeProfiler::enabled;
#endif
#ifdef DRWN_USE_WIN32THREADS
_nThreads = (size > MAX_THREADS) ? MAX_THREADS : size;
if (_nThreads > 0) {
_threads = new HANDLE[_nThreads];
_args = new drwnThreadArgs[_nThreads];
}
InitializeConditionVariable(&_cond);
InitializeCriticalSection(&_mutex);
_bQuit = true;
_bProfilerEnabled = drwnCodeProfiler::enabled;
#endif
}
示例6: YabThreadStart
int YabThreadStart(unsigned int id, void (*func)(void *), void *arg)
{
if (!hnd_key_once)
{
hnd_key=TlsAlloc();
hnd_key_once = 1;
}
if (thread_handle[id].running)
{
fprintf(stderr, "YabThreadStart: thread %u is already started!\n", id);
return -1;
}
// Create CS and condition variable for thread
InitializeCriticalSection(&thread_handle[id].mutex);
InitializeConditionVariable(&thread_handle[id].cond);
thread_handle[id].func = func;
thread_handle[id].arg = arg;
if ((thread_handle[id].thd = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)wrapper, &thread_handle[id], 0, NULL)) == NULL)
{
perror("CreateThread");
return -1;
}
thread_handle[id].running = 1;
return 0;
}
示例7: session_alloc
/* session creation */
static int session_alloc(
IN nfs41_client *client,
OUT nfs41_session **session_out)
{
nfs41_session *session;
int status = NO_ERROR;
session = calloc(1, sizeof(nfs41_session));
if (session == NULL) {
status = GetLastError();
goto out;
}
session->client = client;
session->renew_thread = INVALID_HANDLE_VALUE;
session->isValidState = FALSE;
InitializeCriticalSection(&session->table.lock);
InitializeConditionVariable(&session->table.cond);
init_slot_table(&session->table);
//initialize session lock
InitializeSRWLock(&client->session_lock);
/* initialize the back channel */
nfs41_callback_session_init(session);
*session_out = session;
out:
return status;
}
示例8: pthread_cond_init
/**
@Status Caveat
@Notes Ignores Error codes, ignores error cases
*/
extern "C" int pthread_cond_init(pthread_cond_t* condvar, const pthread_condattr_t* attr) {
CONDITION_VARIABLE* cond = new CONDITION_VARIABLE();
memset(cond, 0, sizeof(CONDITION_VARIABLE));
InitializeConditionVariable(cond);
*condvar = (pthread_cond*)cond;
return 0;
}
示例9: barrier_init
void barrier_init(barrier_t *barrier, int value)
{
InitializeConditionVariable(&barrier->cond);
InitializeCriticalSection(&barrier->mutex);
barrier->value = value;
barrier->counter = 0;
}
示例10: tMPI_Thread_barrier_init
int tMPI_Thread_barrier_init(tMPI_Thread_barrier_t *barrier, int n)
{
if(barrier==NULL)
{
return EINVAL;
}
barrier->barrierp=(struct tMPI_Thread_barrier*)
tMPI_Malloc(sizeof(struct tMPI_Thread_barrier)*1);
#if 0
/* use this once Vista is the oldest supported windows version: */
InitializeCriticalSection(&(barrier->barrierp->cs));
InitializeConditionVariable(&(barrier->barrierp->cv));
#else
tMPI_Thread_mutex_init(&(barrier->barrierp->cs));
tMPI_Thread_cond_init(&(barrier->barrierp->cv));
#endif
barrier->threshold = n;
barrier->count = n;
barrier->cycle = 0;
return 0;
}
示例11: ThreadCVImpl
inline WinThreadCVImpl::WinThreadCVImpl ()
: ThreadCVImpl()
, m_mutex()
, m_waiters(0)
, m_wakeups(0)
{
InitializeConditionVariable(& m_cond);
}
示例12: InitializeConditionVariable
C_CondVar::C_CondVar()
{
#ifdef _WIN32
InitializeConditionVariable(&m_Cond);
#else
pthread_cond_init(&m_Cond,NULL);
#endif
}
示例13: oskar_condition_init
static void oskar_condition_init(oskar_ConditionVar* var)
{
oskar_mutex_init(&var->lock);
#if defined(OSKAR_OS_WIN)
InitializeConditionVariable(&var->var);
#else
pthread_cond_init(&var->var, NULL);
#endif
}
示例14: ConditionCreate
inline Condition*
ConditionCreate()
{
Condition* condition = new Condition;
InitializeConditionVariable(condition);
return condition;
}
示例15: __bctbx_WIN_cond_init
int __bctbx_WIN_cond_init(bctbx_cond_t *cond, void *attr)
{
#ifdef BCTBX_WINDOWS_DESKTOP
*cond=CreateEvent(NULL, FALSE, FALSE, NULL);
#else
InitializeConditionVariable(cond);
#endif
return 0;
}