void* handle1(void* arg){ mtx.lock(); std::cout<<"thread1 before add:"<<cnt<<std::endl; cnt++; std::cout<<"thread1 after add: "<<cnt<<std::endl; mtx.unlock(); sleep(2); }
void* handle2(void* arg){ while(1){ mtx.lock(); std::cout<<"thread2 before add:"<<cnt<<std::endl; cnt++; std::cout<<"thread2 after add: "<<cnt<<std::endl; mtx.unlock(); sleep(2); } }
void scriptMarkStack(hx::MarkContext *__inCtx) { MyMutex *m = sCppiaCtxLock; if (m) m->Lock(); for(int i=0;i<sAllContexts.size();i++) sAllContexts[i]->mark(__inCtx); if (m) m->Unlock(); }
Dynamic __hxcpp_thread_create(Dynamic inStart) { g_threadInfoMutex.Lock(); int threadNumber = g_nextThreadNumber++; g_threadInfoMutex.Unlock(); hxThreadInfo *info = new hxThreadInfo(inStart, threadNumber); hx::GCPrepareMultiThreaded(); hx::EnterGCFreeZone(); #if defined(HX_WINRT) try { auto workItemHandler = ref new WorkItemHandler([=](IAsyncAction^) { // Run the user callback. hxThreadFunc(info); }, Platform::CallbackContext::Any); ThreadPool::RunAsync(workItemHandler, WorkItemPriority::Normal, WorkItemOptions::None); }