本文整理汇总了C++中std::thread::get_id方法的典型用法代码示例。如果您正苦于以下问题:C++ thread::get_id方法的具体用法?C++ thread::get_id怎么用?C++ thread::get_id使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::thread
的用法示例。
在下文中一共展示了thread::get_id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: join
void DeterministicSchedule::join(std::thread& child) {
auto sched = tls_sched;
if (sched) {
bool done = false;
while (!done) {
beforeSharedAccess();
done = !sched->active_.count(child.get_id());
if (done) {
FOLLY_TEST_DSCHED_VLOG("joined " << std::hex << child.get_id());
}
afterSharedAccess();
}
}
child.join();
}
示例2: runtime_error
_R sync(_Function& work, const _Args&... args) {
if (std::this_thread::get_id() != thread_.get_id()) {
std::lock_guard<std::recursive_mutex> api_lock(api_mutex_);
if (!is_running_) {
throw std::runtime_error("Not running");
}
std::promise<_R> promise;
{
std::lock_guard<std::mutex> lock(works_mutex_);
works_.push_back([&promise, &work, &args...]() {
try {
promise.set_value(work(args...));
}
catch (...) {
promise.set_exception(std::current_exception());
}
});
workable_.notify_all();
}
// Make sync
return promise.get_future().get();
}
else {
if (!is_running_) {
throw std::runtime_error("Not running");
}
return work(args...);
}
}
示例3:
~async_message_loop()
{
if(thread.get_id() != std::thread::id()){
DWORD id = ::GetThreadId(thread.native_handle());
::PostThreadMessageW(id, WM_QUIT, 0, 0);
thread.join();
}
}
示例4: start_message_loop
bool start_message_loop()
{
if(thread.get_id() != std::thread::id())
return false;
thread = std::thread([this](){
if(::CoInitialize(nullptr))
return;
::quote::win32::message_loop([this](){
if(queue.empty()){
::Sleep(1);
return;
}
std::shared_ptr<async_message> message;
if(queue.try_pop(message)){
switch(message->message){
case async_message::message_type::create:
{
auto param = reinterpret_cast<creation_params*>(message->data.get());
HWND hwnd = ::CreateWindowExW(
param->exstyle,
param->classname,
param->title,
param->style,
param->x,
param->y,
param->w,
param->h,
param->hparent,
nullptr,
::GetModuleHandleW(nullptr),
param->data);
message->result = hwnd != nullptr;
std::lock_guard<std::mutex> lock(message->mutex);
message->cv.notify_one();
}
break;
case async_message::message_type::destroy:
{
message->result = ::DestroyWindow(reinterpret_cast<HWND>(message->data.get())) != 0;
std::lock_guard<std::mutex> lock(message->mutex);
message->cv.notify_one();
}
break;
}
}
});
::CoUninitialize();
});
return true;
}
示例5: cleanupThread
// Helper function for cleaning up the thread in use
inline void cleanupThread(std::thread &t)
{
if (t.joinable())
{
t.join();
}
else if (t.get_id() != std::thread::id())
{
t.detach();
}
}
示例6: IsGPUThread
bool IsGPUThread()
{
const SConfig& _CoreParameter = SConfig::GetInstance();
if (_CoreParameter.bCPUThread)
{
return (s_emu_thread.joinable() && (s_emu_thread.get_id() == std::this_thread::get_id()));
}
else
{
return IsCPUThread();
}
}
示例7: stop
void stop()
{
if (mThread.get_id() != std::thread::id())
{
mQuit.store(true);
mThread.join();
}
alSourceRewind(mSource);
alSourcei(mSource, AL_BUFFER, 0);
mBufferIdx = 0;
}
示例8: runtime_error
static inline void
set_affinity(std::thread &t, int n)
{
if(t.get_id() == std::thread::id())
throw std::runtime_error("thread not running");
cpu_set_t cpuset;
CPU_ZERO(&cpuset); CPU_SET(n, &cpuset);
auto pth = t.native_handle();
if ( ::pthread_setaffinity_np(pth, sizeof(cpuset), &cpuset) != 0)
throw std::runtime_error("pthread_setaffinity_np");
}
示例9: IsGPUThread
bool IsGPUThread()
{
const SCoreStartupParameter& _CoreParameter =
SConfig::GetInstance().m_LocalCoreStartupParameter;
if (_CoreParameter.bCPUThread)
{
return (g_EmuThread.joinable() && (g_EmuThread.get_id() == std::this_thread::get_id()));
}
else
{
return IsCPUThread();
}
}
示例10: async
void async(std::function<void(void)>&& work) {
if (std::this_thread::get_id() != thread_.get_id()) {
std::lock_guard<std::recursive_mutex> api_lock(api_mutex_);
if (!is_running_) {
return;
}
std::lock_guard<std::mutex> lock(works_mutex_);
works_.push_back(work);
workable_.notify_all();
}
else {
if (!is_running_) {
return;
}
std::lock_guard<std::mutex> lock(works_mutex_);
works_.push_back(work);
workable_.notify_all();
}
}
示例11:
~OpenALStream()
{
if (mThread.get_id() != std::thread::id())
{
/* Tell the thread to quit and wait for it to stop. */
mQuit.store(true);
mThread.join();
}
if (mSource)
{
/* Stop the source, remove the buffers, then put it back so it can
* be used again.
*/
alSourceRewind(mSource);
alSourcei(mSource, AL_BUFFER, 0);
mManager->mFreeSources.push_front(mSource);
}
/* Delete the buffers used for the queue. */
alDeleteBuffers(static_cast<ALsizei>(mBuffers.size()), mBuffers.data());
}
示例12: play
void play()
{
/* If the source is already playing (thread exists and isn't stopped),
* don't do anything.
*/
if (mThread.get_id() != std::thread::id())
{
if (!mQuit.load())
return;
mThread.join();
}
/* Reset the source and clear any buffers that may be on it. */
alSourceRewind(mSource);
alSourcei(mSource, AL_BUFFER, 0);
mBufferIdx = 0;
mQuit.store(false);
/* Start the background thread processing. */
mThread = std::thread(std::mem_fn(&OpenALStream::backgroundProc), this);
}
示例13: IsCPUThread
bool IsCPUThread()
{
return (s_cpu_thread.joinable() ? (s_cpu_thread.get_id() == std::this_thread::get_id()) : !s_is_started);
}
示例14: IsCPUThread
bool IsCPUThread()
{
return (g_cpu_thread.joinable() ? (g_cpu_thread.get_id() == std::this_thread::get_id()) : !g_bStarted);
}
示例15:
std::thread::id
get_id() const
{
return t_.get_id();
}