- 论坛徽章:
- 0
|
本帖最后由 jlccwss 于 2010-08-12 16:56 编辑
- int insert_item(ITEM item)
- {
- if(tail_>= size_)
- {
- tail_ %= size_;
- }
- if((tail_ + 1) != head_)
- {
- //printf("The queue is full\n");
- item_buf_[tail_++] = item;
- return 0;
- }
- else
- return -1;
- }
- ITEM remove_item()
- {
- if(head_>= size_)
- {
- head_ %= size_;
- }
- if(head_ == tail_)
- {
- //printf("The queue is epmty\n");
- return NULL;
- }
- else
- return item_buf_[head_++];
- }
复制代码 insert_item
remove_item
主要看这两个方法的实现,
在insert的时候,如果((tail_ + 1) != head_)就丢掉此次插入的数据
在remove的时候,如果(head_ == tail_)就返回NULL
请高人指点小弟下,没有用锁,这个会有什么问题。item_buf_这个空间是当数组队列来用的。
一会线程存,一个线程取
除了会丢失数据,还会有别的问题么? |
|