当前位置: 首页>>代码示例>>C++>>正文


C++ thread::native_handle方法代码示例

本文整理汇总了C++中std::thread::native_handle方法的典型用法代码示例。如果您正苦于以下问题:C++ thread::native_handle方法的具体用法?C++ thread::native_handle怎么用?C++ thread::native_handle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在std::thread的用法示例。


在下文中一共展示了thread::native_handle方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: setPriority

void setPriority(std::thread& t, ThreadPriorityClass priorityClass,
                 ThreadPriorityLevel priorityLevel)
{
#ifdef WIN32
    std::thread::native_handle_type h = t.native_handle();

    SetPriorityClass(h, convertThreadPriorityClass(priorityClass));
    SetThreadPriority(h, convertThreadPriorityLevel(priorityClass, priorityLevel));
#else
    int policy;
    struct sched_param param;
    int res = pthread_getschedparam(t.native_handle(), &policy, &param);
    if (res != 0) {
        throw ghoul::RuntimeError(
            "Error accessing scheduling parameters with error " + std::to_string(res),
            "Thread"
        );
    }

    param.sched_priority = convertThreadPriorityLevel(priorityClass, priorityLevel);
    res = pthread_setschedparam(
        t.native_handle(),
        policy,
        &param
    );
    if (res != 0) {
        throw ghoul::RuntimeError(
            "Error setting scheduling parameters with error " + std::to_string(res),
            "Thread"
        );
    }
#endif
}
开发者ID:OpenSpace,项目名称:Ghoul,代码行数:33,代码来源:thread.cpp

示例2:

		~async_message_loop()
		{
			if(thread.get_id() != std::thread::id()){
				DWORD id = ::GetThreadId(thread.native_handle());
				::PostThreadMessageW(id, WM_QUIT, 0, 0);
				thread.join();
			}
		}
开发者ID:quartorz,项目名称:quote,代码行数:8,代码来源:async_message_loop.hpp

示例3: TimerObjectReactor

    explicit TimerObjectReactor(DataObjectReactor& dor) : _epfd(-1), _evtfd(-1), _dor(dor) {
#ifdef __linux__
        if ((_evtfd = ::eventfd(0, EFD_CLOEXEC)) < 0) {
            Logger::pLOG->error("Eventfd file handle could not be created in TOR: {}", std::strerror(errno));
            return;
        }

        if ((_epfd = ::epoll_create1(EPOLL_CLOEXEC)) < 0) {
            Logger::pLOG->error("Epoll file handle could not be created in TOR: {}", std::strerror(errno));
            close(_evtfd);
            return;
        }

        // Add it first to stop epoll_wait in case of destruction
        epoll_event evt {};
        evt.events = EPOLLIN;
        evt.data.fd = _evtfd;

        if (::epoll_ctl(_epfd, EPOLL_CTL_ADD, _evtfd, &evt) < 0) {
            Logger::pLOG->error("Epoll control error at ADD stop event in TOR: {}", std::strerror(errno));
            close(_epfd);
            close(_evtfd);
            return;
        }

        _thrd = std::thread([this](){ TimerObjectReactor::run(); });

        //The thread name is a meaningful C language string, whose length is
        //restricted to 16 characters, including the terminating null byte ('\0')
        std::string s = "TOR-THRD-0";
        Logger::pLOG->info("Created {}", s);

        if (pthread_setname_np(_thrd.native_handle(), s.data()))
            Logger::pLOG->warn("Could not set name for {}", s);

        struct sched_param param {};
        param.sched_priority = RT_PRIO;

        if (pthread_setschedparam(_thrd.native_handle(), SCHED_FIFO, &param))
            Logger::pLOG->warn("Could not set realtime parameter for {}", s);
#endif
    }
开发者ID:AbstractStateMachine,项目名称:concept,代码行数:42,代码来源:timerobjectreactor.hpp

示例4: stop

 int stop() {
   Logger logdev = Logger::getInstance(LOGDEVICE);
   if (running) {
     running = false;
     // Native pthread_cancel due blocking read that consume less cpu then timed select
     pthread_cancel(key_thread.native_handle());
     key_thread.join();
     close(fd);
     fd = -1;
   }
   LOG4CPLUS_DEBUG(logdev, "key reader stopped");
   return (0);
 }
开发者ID:danieleatgithub,项目名称:Homer,代码行数:13,代码来源:KeyPanel.hpp

示例5: 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");
    }
开发者ID:jkhoogland,项目名称:PFQ,代码行数:13,代码来源:affinity.hpp

示例6: assert

void RequestQueueImplWorker::StopThread(
    std::thread& t, common::SharedState<ThreadState>& s, common::Semaphore& sem) {
    assert(s() == RUNNING);
    s.set_to(TERMINATING);
    sem.signal();
#if THRILL_MSVC >= 1700
    // In the Visual C++ Runtime 2012 and 2013, there is a deadlock bug, which
    // occurs when threads are joined after main() exits. Apparently, Microsoft
    // thinks this is not a big issue. It has not been fixed in VC++RT 2013.
    // https://connect.microsoft.com/VisualStudio/feedback/details/747145
    //
    // All threads are created by singletons, which are global variables that
    // are deleted after main() exits. The fix applied here it to use
    // std::thread::native_handle() and access the WINAPI to terminate the
    // thread directly (after it finished handling its i/o requests).

    WaitForSingleObject(t->native_handle(), INFINITE);
    CloseHandle(t->native_handle());
#else
    t.join();
#endif
    assert(s() == TERMINATED);
    s.set_to(NOT_RUNNING);
}
开发者ID:Cyaagain,项目名称:thrill,代码行数:24,代码来源:request_queue_impl_worker.cpp

示例7: SetCpuAffinity

void SetCpuAffinity(std::thread& thread, size_t cpu_id) {
#if __linux__ && !THRILL_ON_TRAVIS
    cpu_set_t cpuset;
    CPU_ZERO(&cpuset);
    CPU_SET(cpu_id % std::thread::hardware_concurrency(), &cpuset);
    int rc = pthread_setaffinity_np(
        thread.native_handle(), sizeof(cpu_set_t), &cpuset);
    if (rc != 0) {
        LOG1 << "Error calling pthread_setaffinity_np(): "
             << rc << ": " << strerror(errno);
    }
#else
    tlx::unused(thread);
    tlx::unused(cpu_id);
#endif
}
开发者ID:bingmann,项目名称:thrill,代码行数:16,代码来源:porting.cpp

示例8: bind

bool Core::bind(std::thread& thread)
{
    auto cpuset = hwloc_bitmap_dup(core_->cpuset);
    hwloc_bitmap_singlify(cpuset);

    if (hwloc_set_thread_cpubind(topology_, thread.native_handle(), cpuset, 0))
    {
        auto error = errno;
        LOG(thread_logger, warning) << "Error setting thread affinity: "
                                    << strerror(error);
        hwloc_bitmap_free(cpuset);
        return false;
    }

    hwloc_bitmap_free(cpuset);
    return true;
}
开发者ID:asyr625,项目名称:commonpp,代码行数:17,代码来源:Core.cpp

示例9: setThreadBackground

void setThreadBackground(std::thread& t, Background background) {
    int m = background ? THREAD_MODE_BACKGROUND_BEGIN : THREAD_MODE_BACKGROUND_END;
    std::thread::native_handle_type h = t.native_handle();
    SetThreadPriority(h, m);
}
开发者ID:OpenSpace,项目名称:Ghoul,代码行数:5,代码来源:thread.cpp


注:本文中的std::thread::native_handle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。