ratio_controlbuf_vs_show_buf
来源:互联网 发布:数据录入查询系统源码 编辑:程序博客网 时间:2024/05/22 04:51
解决程序运行一段时间程序莫名奇妙挂起的bug
toshow writefile读取线程 和interp_to_show 写入 控制多长个时间运行一次用的define 宏 通过判断count%宏的值==0 ,来判断是否到达时刻,当宏的值大于1时,出现了 一直写入,只能读取一次的情况,当define的宏设为1时,两者速度匹配,但是如果设为别的数值,则两者不匹配,来设置得到正在查找原因;
解决方案:
现象---showbuffer很快满了,---推理,信号量开锁阶段,解锁阶段没有进行执行次数的判断(信号量操作的问题)
解决方案如下:
消费者
#define ratio_controlbuf_vs_show_buf 5
/*sem_wait对信号量进行加减操作,所以也需要加 if(cycle_count_show%ratio_controlbuf_vs_show_buf==0) 来匹配读写次数,否则就会有问题*/
if(cycle_count_show%ratio_controlbuf_vs_show_buf==0)
{
sem_wait(&(shared_motor_time_related_to_show->full_sem));
pthread_mutex_lock(&(shared_motor_time_related_to_show->mutex));
sem_wait(&(shared_axis_time_related_to_show->full_sem));
pthread_mutex_lock(&(shared_axis_time_related_to_show->mutex));
}
if(cycle_count_show%ratio_controlbuf_vs_show_buf==0)
{
for(int i=0;i<sys_axis_num;i++)
{
real_read_axis=deQueue();
real_read=deQueue();
}
data_num_in_buffer2=lenQueue();
}
if(real_read_axis!=0)
{
data_num_in_buffer_axis=lenQueue<arrQueue_data_axis_time_related>(&(shared_axis_time_related_to_show->plan_buffer_first_stage_to_show[0]));
printf("axis_read_customer reads %d bytes from the FIFO successfully! \n",real_read_axis);
printf("Now,the axis_plan_buffer left %d spaces!\n",data_num_in_buffer_axis);
}//end if(real_read_axis!=0)
}//end if(cycle_count_show%ratio_controlbuf_vs_show_buf==0)
if(cycle_count_show%ratio_controlbuf_vs_show_buf==0)
{
pthread_mutex_unlock(&(shared_axis_time_related_to_show->mutex));
sem_post(&(shared_axis_time_related_to_show->empty_sem));
pthread_mutex_unlock(&(shared_motor_time_related_to_show->mutex));
sem_post(&(shared_motor_time_related_to_show->empty_sem));
}
cycle_count_show++;//一定要放在 pthread_mutex_unlock sem_post之后
- ratio_controlbuf_vs_show_buf
- POJ
- MySQL多表查询
- 深度学习资料
- C++ 文件和流
- 多元函数的高阶微分公式 与 Taylor公式
- ratio_controlbuf_vs_show_buf
- 正则式分段提取中文,看不懂啊,先记录下来
- 最小费用流模板(Bellman-Ford算法找最短路)
- 短视频sdk:选择一个靠谱的短视频SDK 你需要了解这些
- certbot-auto 生成nginx证书指定nginx配置路径
- Matlab 文件路径总结
- 86-partition list
- 2017.11.3 队测T2 death
- JavaScripts中的this指向及call、apply详解