boost::lockfree中的"wait-free"到底是什么意思?

What exactly is the meaning of "wait-free" in boost::lockfree?

我正在阅读 spsc_queue 的文档,即使在其他地方阅读了一些之后,我也不完全相信 "wait-free" 的含义。

它们到底是什么意思

bool push(T const & t);

Pushes object t to the ringbuffer.

Note: Thread-safe and wait-free

我的意思是必须有一些同步开销。是

some_spscqueue.push(x);

保证花费一定的时间?它与非线程安全队列相比如何?

PS: 别担心,我要测量了,但是由于我天真的无知,我无法想象一个不涉及某种等待的同步机制,我很困惑什么"wait-free" 应该告诉我。

A wait-free implementation of a concurrent data object is one that guarantees that any process can complete any operation in a finite number of steps, regardless of the execution speeds of the other processes.

(来自 Herlihy 文章的 abstract)。

另请参阅 Wikipedia,以及您通过在搜索引擎中输入“等待免费”立即找到的所有其他资源。

所以无等待并不意味着没有延迟,它意味着你永远不会进入阻塞等待状态,并且可以'不会被无限期封锁 and/or 饿死。

换句话说,wait 具有特定的技术含义,即您的线程处于停放状态(并且在被唤醒之前不执行任何指令),或者处于循环中等待满足某些外部条件(例如自旋锁)。如果它从未被唤醒,或者如果它被唤醒但总是发现它无法继续并且必须再次等待,或者如果循环永远不会退出,那么你的线程正在饿死并且无法取得进展。

每个操作都有 一些 延迟,而无等待并没有说明 任何 是什么。

How does it compare to a non-thread safe queue?

它几乎肯定会比完全不同步的容器更昂贵,因为您仍在做额外的工作(假设您确实只从单个线程访问容器)。

"Pushes object to the ring buffer"指的是实现队列的数组缓冲区的类型。这可能是使用循环数组将对象存储在队列中来实现的。参见示例:

https://en.wikipedia.org/wiki/Circular_buffer

http://opendatastructures.org/ods-python/2_3_ArrayQueue_Array_Based_.html