System V消息队列报Resource temporarily unavailable 错误
项目场景:
使用System v 消息队列,进行线程间数据通讯。msgsnd()函数作为生产者,msgrcv()函数当作消费者。
问题描述:
当大事件量数据的时候会出现 Resource temporarily unavailable 错误。在常规情况下不会产生此错误。
原因分析:
经过对代码的分析,当有大事件数据触发时会产生消费者,消费者msgrcv()处理的时间较长,速度较慢。生产者msgsnd()在非阻塞的模式下,无法将数据放入到消息队列而报错。
int queue_create(queue_inst_t *a_p_inst) {if (a_p_inst == NULL ) {printf("queue_create invalid arguments\n");return -1;}int idx;for (idx = 0; idx < MBOX_MAX_NUM; idx++) {if (sg_mbox[idx].m_is_used == false) {sg_mbox[idx].m_is_used = true;break;}}if (idx == MBOX_MAX_NUM) {return -1;}a_p_inst->m_idx = idx;sprintf(sg_mbox[idx].m_queueName, "/tmp/queue_%d", idx);FILE *file = fopen(sg_mbox[idx].m_queueName, "a");if (file == NULL ) {printf("fopen %s failed, Err: %s\n", sg_mbox[idx].m_queueName,strerror(errno));return -