Visual Studio 2017 包含一个xthreads.h
与threads.h
. 例如:
来自https://en.cppreference.com/w/c/thread/thrd_sleep
#include <threads.h>
#include <time.h>
#include <stdio.h>
int main(void)
{
printf("Time: %s", ctime(&(time_t){time(NULL)}));
thrd_sleep(&(struct timespec){.tv_sec=1}, NULL); // sleep 1 sec
printf("Time: %s", ctime(&(time_t){time(NULL)}));
}
将会
#include <thr/xthreads.h>
#include <time.h>
#include <stdio.h>
int main(void)
{
struct xtime stoptime;
xtime_get( &stoptime, 1);
stoptime.sec += 1;
printf("Time: %s", ctime(&(time_t){time(NULL)}));
_Thrd_sleep( &stoptime );
printf("Time: %s", ctime(&(time_t){time(NULL)}));
}
* 注意:xthreads.h
不是标准的,因此可能会发生变化。*
https://gist.github.com/yohhoy/2223710上还有一个仿真库。