void ThreadTest::workerThread() { m_mutex.acquire(); m_workerRunning = true; m_startedCondition.broadcast(); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%t Thread running, waiting for stop condition.\n"))); if (m_doubleLock) { ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%t Thread starting double acquire.\n"))); m_mutex.acquire(); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%t Thread finished double acquire.\n"))); } // Wait for the STOP condition to occur m_stopCondition.wait(); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%t Thread received stop condition, exiting.\n"))); if (m_doubleLock) { ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%t Thread starting double release.\n"))); m_mutex.release(); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%t Thread finished double acquire.\n"))); } m_mutex.release(); }
// returns 0 on success to take mutex, -1 on genric failure of releasing mutex, -2 on failure upon null pointer. m is pointer obtained w/ ace_mutex_new(), int8_t ace_mutex_release(void* m) { ACE_Recursive_Thread_Mutex* acemtx = (ACE_Recursive_Thread_Mutex*)m; if(NULL == acemtx) { return(-2); } acemtx->release(); return(0); }
int ThreadTest::run(bool doubleLock) { ACE_hthread_t m_workerThreadHandle; ACE_thread_t m_workerThreadId; m_workerRunning = false; m_doubleLock = doubleLock; m_mutex.acquire(); // Start worker thread int rval = ACE_Thread::spawn((ACE_THR_FUNC) workerThreadWrapper, this, THR_JOINABLE | THR_NEW_LWP, &m_workerThreadId, &m_workerThreadHandle, ACE_DEFAULT_THREAD_PRIORITY); if (rval == -1) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%t Could not start worker thread!\n")), 1); } if (!m_workerRunning) { ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%t Waiting for worker thread to start running...\n"))); m_startedCondition.wait(); } ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%t Worker thread is running...\n"))); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%t Broadcasting STOP Condition...\n"))); m_stopCondition.broadcast(); m_mutex.release(); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%t Joining worker thread...\n"))); ACE_Thread::join(m_workerThreadHandle); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%t Test finished...\n"))); return 0; }