本文整理汇总了C++中thread类的典型用法代码示例。如果您正苦于以下问题:C++ thread类的具体用法?C++ thread怎么用?C++ thread使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了thread类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: average
average(){
sum = 0;
delete_thread_run = true;
life = chrono::seconds(10);
del = thread(&average::deleteOldData, this);
if(del.joinable()) del.detach();
}
开发者ID:liuyifly06,项目名称:data_structure_and_algorithms,代码行数:7,代码来源:MeanOfDataStream.cpp
示例2: operator
void operator()(thread& t)
{
if (t.joinable())
{
t.join();
}
}
开发者ID:cboulay,项目名称:labstreaminglayer,代码行数:7,代码来源:thread_functors.hpp
示例3: print_id
void print_id(thread& t)
{
if (t.get_id()==thread::id{})
cout << "t not joinable\n";
else
cout << "t's id is " << t.get_id() << '\n';
}
开发者ID:sasaki-seiji,项目名称:ProgrammingLanguageCPP4th,代码行数:7,代码来源:thread_id.cpp
示例4: join
void join()
{
if(!thread_.joinable())
return;
should_stop_ = true;
thread_.join();
}
开发者ID:rodrigostrauss,项目名称:tio,代码行数:10,代码来源:tiobench.cpp
示例5: stop
void stop()
{
if(thread_.joinable())
{
{
lock_guard lock{m_};
stop_ = true;
}
cond_.notify_all();
thread_.join();
}
}
开发者ID:dreamsxin,项目名称:rippled,代码行数:12,代码来源:basic_seconds_clock.hpp
示例6: beat
void beat()
{
static ServerInfo info;
info = Server->getInfo();
static thread hb;
if(hb.timed_join(milliseconds(0)))
{
hb = thread( doHeartBeat,std::ref(info));
Tasks->callLater(60000,beat);
}
}
开发者ID:TheArchives,项目名称:ArMCpp,代码行数:13,代码来源:Heartbeat.cpp
示例7: obs_module_unload
void obs_module_unload(void)
{
#ifdef USE_QT_LOOP
BrowserShutdown();
#else
if (manager_thread.joinable()) {
while (!QueueCEFTask([] () {CefQuitMessageLoop();}))
os_sleep_ms(5);
manager_thread.join();
}
#endif
os_event_destroy(cef_started_event);
}
开发者ID:kc5nra,项目名称:obs-browser,代码行数:15,代码来源:obs-browser-plugin.cpp
示例8: stop
void stop()
{
if(!thread_.joinable())
return;
should_stop_ = true;
}
开发者ID:rodrigostrauss,项目名称:tio,代码行数:7,代码来源:tiobench.cpp
示例9: run
uint32_t run()
{
m_actual->m_state = thread::STARTED;
m_actual->m_return = m_actual->run();
m_actual->m_state = thread::COMPLETED;
return m_actual->m_return;
}
开发者ID:kurtism-lmb,项目名称:u50s,代码行数:7,代码来源:thread.cpp
示例10: test_A3_c
bool test_A3_c() {
#ifdef A3_c
stop_thread();
return (!T.joinable());
#else
return false;
#endif
}
开发者ID:DerNerger,项目名称:CppProjects,代码行数:8,代码来源:A3.cpp
示例11: rng_finilize
void rng_finilize()
{
rng_producer_done = true;
rng_producer_thread.join();
/* Cleanup */
curandDestroyGenerator(gen);
cudaFree(devData);
}
开发者ID:revitmt,项目名称:misc,代码行数:9,代码来源:rnd_generator.cpp
示例12: thread_id
string CriticalSection::thread_id(thread& t)
{
string id;
stringstream s;
s << t.get_id();
s >> id;
return id;
}
开发者ID:TheMw3Wolv,项目名称:Vault-Tec-Multiplayer-Mod,代码行数:10,代码来源:CriticalSection.cpp
示例13:
JNIEXPORT jint JNICALL Java_org_iotivity_ResourceHosting_ResourceHosting_OICCoordinatorStop
(JNIEnv *env, jobject obj)
{
jint result = 0;
//terminate Thread
if (ocProcessThread.joinable())
{
threadRun = false;
ocProcessThread.join();
}
else
{
result = (jint)HOSTING_THREAD_ERROR;
return result;
}
result = (jint)OICStopCoordinate();
return result;
}
开发者ID:InfiniteDevelopment,项目名称:iotivity,代码行数:19,代码来源:ResourceHosing_JNI.cpp
示例14: return
JNIEXPORT jint JNICALL Java_org_iotivity_ResourceHosting_ResourceHosting_ResourceHostingTerminate
(JNIEnv *env, jobject obj)
{
if (OCStop() != OC_STACK_OK)
{
return (jint)OCSTACK_ERROR;
}
//terminate Thread
if (ocProcessThread.joinable())
{
threadRun = false;
ocProcessThread.join();
}
else
{
return (jint)HOSTING_THREAD_ERROR;
}
return (jint)OCSTACK_OK;
}
开发者ID:InfiniteDevelopment,项目名称:iotivity,代码行数:20,代码来源:ResourceHosing_JNI.cpp
示例15: MessageThread
namespace IPC
{
thread messageThread;
HANDLE stopRunning;
static void MessageThread(Application *app) {
while (true) {
// Quit if we were requested to.
if (WaitForSingleObject(stopRunning, 0) != WAIT_TIMEOUT)
return;
try {
MessageQueue mq("BunnymodXT-TASView");
vector<char> buf(256);
DWORD bytesRead;
while (true) {
if (mq.timed_read(buf, 1s, bytesRead, stopRunning))
app->ParseMessage(buf, bytesRead);
// Quit if we were requested to.
if (WaitForSingleObject(stopRunning, 0) != WAIT_TIMEOUT)
return;
}
} catch (const exception& ex) {
// Wait 1s before trying again. Quit if we were requested to at any point during this waiting.
cerr << "Exception: " << ex.what() << "\n";
if (WaitForSingleObject(stopRunning, 1000) != WAIT_TIMEOUT)
return;
}
}
}
void StartReceivingMessages(Application *app)
{
stopRunning = CreateEvent(NULL, TRUE, FALSE, NULL);
if (!stopRunning)
throw runtime_error("CreateEvent failed: "s + to_string(GetLastError()) + "\n"s);
messageThread = thread(MessageThread, app);
}
void StopReceivingMessages()
{
if (SetEvent(stopRunning)) {
messageThread.join();
} else {
cerr << "SetEvent failed: " << GetLastError() << "\n";
messageThread.detach();
}
}
}
开发者ID:YaLTeR,项目名称:TASView,代码行数:52,代码来源:IPC.cpp
示例16: startSim
void startSim(int* common,int hold1,int hold2,int playerNum,SimType type)
{
stopAndGetRes();
while(running.load())
{
this_thread::sleep_for(std::chrono::milliseconds(2));
}
std::lock_guard<std::mutex> lck (mtx);
sum=win=0;
stop=false;
simThread=move(thread(work,this,common,(int)type,hold1,hold2,playerNum));
simThread.detach();
}
开发者ID:ltf1320,项目名称:hw2015,代码行数:13,代码来源:simulator.hpp
示例17: init
void init(void)
{
if (currentStage != Stage::NOT_INITIALIZED)
throw ShmemAlreadyInitializedException();
shmemBuffer = new char[SHMEM_BUF_SIZE];
strncpy(shmemBuffer, "INIT", SHMEM_BUF_SIZE);
agentThread = thread(agent);
agentThread.detach();
while (!isMsgEqualTo("ACK"));
currentStage = Stage::ACTIVE;
}
开发者ID:shelart,项目名称:shmem,代码行数:13,代码来源:shmem.cpp
示例18: stop_log_rotation
void stop_log_rotation() {
// if no log rotation active, quit.
if (!thread_running) return;
// join the log rotation thread.
lock.lock();
thread_running = false;
cond.signal();
lock.unlock();
log_rotate_thread.join();
// we will continue logging to the same location, but we will
// delete the symlink
unlink(symlink_name.c_str());
}
开发者ID:Hannah1999,项目名称:Dato-Core,代码行数:13,代码来源:log_rotate.cpp
示例19: LOGGER
void SipTransport::sendAxoMessage(const CmdQueueInfo &info, const string& envelope)
{
LOGGER(DEBUGGING, __func__, " -->");
#if !defined(EMSCRIPTEN)
if (!sendThread.joinable()) {
unique_lock<mutex> lck(threadLock);
if (!sendThread.joinable()) {
sendingActive = true;
sendThread = thread(runSendQueue, sendAxoData_, this);
}
lck.unlock();
}
#else
sendingActive = true;
#endif
unique_lock<mutex> listLock(sendListLock);
// Store all relevant data to send a message in a structure, queue the message
// info structure.
shared_ptr<SendMsgInfo> msgInfo = make_shared<SendMsgInfo>();
msgInfo->recipient = info.queueInfo_recipient;
msgInfo->deviceId = info.queueInfo_deviceId;
msgInfo->envelope = envelope;
uint64_t typeMask = (info.queueInfo_transportMsgId & MSG_TYPE_MASK) >= GROUP_MSG_NORMAL ? GROUP_TRANSPORT : 0;
msgInfo->transportMsgId = info.queueInfo_transportMsgId | typeMask;
sendMessageList.push_back(msgInfo);
runSend = true;
sendCv.notify_one();
listLock.unlock();
#if defined(EMSCRIPTEN)
runSendQueue(sendAxoData_, this);
#endif
LOGGER(DEBUGGING, __func__, " <--");
}
开发者ID:SilentCircle,项目名称:libzina,代码行数:39,代码来源:SipTransport.cpp
示例20: runnable_pair_test
void runnable_pair_test(runnable & a, runnable & b)
{
cerr << "Entering runnable_pair_test" << endl;
static thread ut1, ut2;
ut1.start(a);
ut2.start(b);
ut1.join();
ut2.join();
};
开发者ID:fpstovall,项目名称:nrtb_beta,代码行数:9,代码来源:thread_test.cpp
注:本文中的thread类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论