项目作者: r10a

项目描述 :
Standalone Eventcounts module from facebook/folly
高级语言: C++
项目地址: git://github.com/r10a/Event-Counts.git
创建时间: 2019-02-23T23:15:47Z
项目社区:https://github.com/r10a/Event-Counts

开源协议:Apache License 2.0

下载


Event-Counts

Standalone event-count module from facebook’s folly.

An eventcount is a condition variable for lockfree algorithms. That is, it permits a thread to efficiently wait for an arbitrary condition to occur, but unlike condition variables, an eventcount does not require a mutex to protect the state (it’s kind of stupid to surround a lockfree data structure with a mutex to permit conditional waiting).

Eventcounts allow to separate a lockfree data structure and blocking/signaling logic, so that there is generally no need to reimplement and inject it into each and every lockfree algorithm. For example, some people tend to implement so called blocking producer-consumer queues (instead of returning ‘false’ it blocks until new elements available), that’s not only complicates the implementation, it also does not permit to poll, for example, several producer-consumer queues.

More information here.

Usage -

  1. Waiter:
  2. if (!condition()) { // handle fast path first
  3. for (;;) {
  4. auto key = eventCount.prepareWait();
  5. if (condition()) {
  6. eventCount.cancelWait();
  7. break;
  8. } else {
  9. eventCount.wait(key);
  10. }
  11. }
  12. }
  1. Poster:
  2. make_condition_true();
  3. eventCount.notifyAll();

Compile with -DPSHARED flag for use across multiple processes.

Build using cmake and run the demo program from main.cpp