Thread-safe C++ stack

后端 未结 6 1370
余生分开走
余生分开走 2021-01-30 18:56

I\'m new to C++ and am writing a multi-threaded app whereby different writers will be pushing objects onto a stack and readers pulling them off the stack (or at least pushing th

6条回答
  •  长发绾君心
    2021-01-30 19:10

    If you are running on Windows, SLIST implements a lockfree stack (with the structures SLIST_HEADER & SLIST_ENTRY).

    The algorithm is implemented using fairly trivial push/pop singly linked list stack using interlocked functions. The only non-obvious item is the counter increment to avoid ABA issues.

提交回复
热议问题