concurrentqueue icon indicating copy to clipboard operation
concurrentqueue copied to clipboard

How do I clear the cache with explicit tokens

Open GREATwo opened this issue 3 years ago • 4 comments

  1. If multiple threads are enqueued without explicit tokens, how to ensure that the order of enqueueing is the same as the order of enqueueing

  2. How can I clear the cache if I use explicit tokens

  3. In the latest version, implicit tokens are used to free up memory, which is nice

GREATwo avatar Mar 08 '22 09:03 GREATwo

  1. With or without explicit tokens, the final dequeue order is not guaranteed. Only the ordering between elements enqueued by the same thread (implicit) or token (explicit) is preserved. This is covered in the README.
  2. If you're asking how to clear the queue in a thread-safe way, you must dequeue all elements. If you're referring to reducing memory usage after elements have been dequeued: destroying the token will not free any excess blocks (which account for most of the memory usage). They will be recycled when another token is created.
  3. Yes :-)

cameron314 avatar Mar 08 '22 12:03 cameron314

If multiple threads share a producer token and lock the token, you can ensure that enqueueing and enqueueing are consistent

GREATwo avatar Mar 09 '22 01:03 GREATwo

If multiple threads share a producer token and lock the token, you can ensure that enqueueing and enqueueing are consistent

Then what's the point of using this data structure? Use std:queue and lock the whole thing instead.

eata7 avatar Mar 09 '22 01:03 eata7

Depends on whether you have concurrent consumers, but if there's just one, then yes, at that point locking during enqueue with a ReaderWriterQueue instead may be better, if you truly need inter-producer order stability.

cameron314 avatar Mar 09 '22 01:03 cameron314