win7平台支持boost sem_timedwait()



有人能告诉我解析timespec结构需要定义的头吗
在win7平台上使用sem_timedwait()时。。。是否支持?注意我没有使用ptheads。。。或进程间信号量使用boost1.5库。。。

这是我所拥有的片段,但不确定还有什么可以包括

#include <boost/thread/mutex.hpp>  
#include <boost/thread/condition.hpp>  
#include <boost/thread/thread.hpp>    
#include <semaphore.h>   
#include <time.h>  
...
sem_init(&sema, 0, 0);      
sem_init(&semb, 0, 0);  
...
struct timespec timeout = { 0, 0 };
clock_gettime( CLOCK_REALTIME, &timeout );
timeout.tv_sec += 5; //5 second timeout 
CU_ASSERT_TRUE(sem_timedwait(&sema,&timeout));   // released by another boost::thread
...

Windows本机不支持pthreads标准,因此您将不得不使用替代方案,例如pthreads-win32。

如果想要使用boost,那么最好使用boost中的内容,在这种情况下,您应该将代码中pthreads信号量的使用替换为boost.interprocess信号量。

最新更新