L*****n 发帖数: 15 | 1 "Implement a circular queue of integers of user-specified size using a
simple array. Provide routines to initialize(), enqueue() and dequeue() the
queue. Make it thread safe."
Using c++
怎么写比较好?多谢! |
j*****o 发帖数: 394 | 2 用一个数组的话
用指针记录头和尾的位置
enqueue这么加: arr[ (tail++)%size ] = val
如果是dequeue 就是HEAD指针“右移” (也要用 %size).
弱问thread safe是啥概念。。不越界就行啦?
the
【在 L*****n 的大作中提到】 : "Implement a circular queue of integers of user-specified size using a : simple array. Provide routines to initialize(), enqueue() and dequeue() the : queue. Make it thread safe." : : Using c++ : 怎么写比较好?多谢!
|
x*******6 发帖数: 262 | 3 c++不懂,java可以把那两个方法synchronized |
L*****n 发帖数: 15 | 4 多谢!我也不清楚thread safe 用到这个题是什么意思。同问。
【在 j*****o 的大作中提到】 : 用一个数组的话 : 用指针记录头和尾的位置 : enqueue这么加: arr[ (tail++)%size ] = val : 如果是dequeue 就是HEAD指针“右移” (也要用 %size). : 弱问thread safe是啥概念。。不越界就行啦? : : the
|
a***o 发帖数: 1182 | 5 多线程,用lock
the
【在 L*****n 的大作中提到】 : "Implement a circular queue of integers of user-specified size using a : simple array. Provide routines to initialize(), enqueue() and dequeue() the : queue. Make it thread safe." : : Using c++ : 怎么写比较好?多谢!
|
L*****n 发帖数: 15 | 6 多谢!我还是不太明白多线程lock的用法。麻烦您写一下好吗?我们大家都好学习下。
非常感谢!
【在 a***o 的大作中提到】 : 多线程,用lock : : the
|
j********e 发帖数: 1192 | 7 他说的估计是用mutex之类的,linux下用pthread_mutex
【在 L*****n 的大作中提到】 : 多谢!我还是不太明白多线程lock的用法。麻烦您写一下好吗?我们大家都好学习下。 : 非常感谢!
|