How do I clear the cache with explicit tokens
-
If multiple threads are enqueued without explicit tokens, how to ensure that the order of enqueueing is the same as the order of enqueueing
-
How can I clear the cache if I use explicit tokens
-
In the latest version, implicit tokens are used to free up memory, which is nice
- 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.
- 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.
- Yes :-)
If multiple threads share a producer token and lock the token, you can ensure that enqueueing and enqueueing are consistent
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.
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.