sem_t sem[PLATMAX_NUM];
sem_t sem_plt;
pthread_mutex_t v2x_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t cond_plat = PTHREAD_COND_INITIALIZER;
struct timeval now;
struct timespec outtime;
while(appd_run_flag.appd_pltfrm_flag==1&&v2x_flag==0)
{
gettimeofday(&now, NULL);
outtime.tv_sec = now.tv_sec + WAIT_TIME;
outtime.tv_nsec = now.tv_usec * 1000;
ret = pthread_cond_timedwait(&cond_plat, &v2x_mutex, &outtime);
if(ret!=0)
{
SPS_LOG_DEBUG_FMT("cond_plt wait timout,ret:%d",ret);
}
else
{
SPS_LOG_DEBUG_FMT("cond_plt get_v2xINfo,ret:%d",ret);
break;
}
v2x_flag=rsi_flag.plt_flag+rsm_flag.plt_flag+spat_flag.plt_flag+map_flag.plt_flag+bsm_flag.plt_flag+vehicle_flag.plt_flag+obj_flag.plt_flag+preempt_flag.plt_flag;
}
//清空标识、区
C++ 参考手册
原子操作
这些组建为细粒度的原子操作提供,允许无锁并发编程。涉及同一对象的每个原子操作,相对于任何其他原子操作是不可分的。原子对象不具有数据竞争。
#include <iostream>
#include <thread>
#include <atomic>
#include <functional>
using namespace std;
struct Counter
{
void increment()
{
for (int i = 0; i < 10; ++i)
{
m_value++;
cout << "increment number: " << m_value
<< ", theadID: " << this_thread::get_id() << endl;
this_thread::sleep_for(chrono::milliseconds(500));
}
}
// atomic<int> == atomic_int
atomic_int m_value;
};
int main()
{
Counter c;
c.m_value = 0;
auto increment = bind(&Counter::increment, &c);
thread t1(increment);
t1.join();
return 0;
}