Cross-platform way of yielding a thread in C/C++?

后端 未结 2 740
生来不讨喜
生来不讨喜 2021-01-18 07:00

In C and C++ is there a cross-platform way of yielding a thread? Something like sched_yield() or Sleep(0)? Does SDL_Delay(0) always yield or will it return immediately in so

2条回答
  •  深忆病人
    2021-01-18 07:21

    in the c++ case, boost::thread::yield() does what you ask. On platforms with posix threads, pthread_yield() performs the same function for C and anything that links with it. On platforms where this doesn't immediately stop the thread and start another, it's because the scheduler doesn't support that functionality. I don't think that many such platforms actually exist in the wild.

提交回复
热议问题