Is it possible to use this queue with any moveable types? #5
-
While going through the code and the associated presentation, it seems that this queue only supports trivial data types. What I didn't fully understand is why this limitation is placed on the queue. Would supporting any moveable type break the requirements that were set out for this queue implementation? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
In order to provide non-blocking atomic operation on the queue entries, each entry must be 16 bytes or less, as the hardware atomic operations which are non-blocking are limited to 16 bytes, ( DWCAS, see below). The Queue requires 32 bits for internal entry state, which leaves the transferable data type to 12 bytes. To use the queue with movable objects of 12 bytes or less, you can see the queue implementation that transfers std::unique_ptr<> in the header file: pointer_mpmc_queue.h - it uses the reset() and release() methods to keep a single owner to the target object. In case you need to transfer bigger objects, you might want to use the std::unique_ptr as the transferable units. You might also use shared_ptr which fits into 8 bytes, ( not std::shared_ptr<> which is 16 bytes) for example boost intrusive shared pointer References: |
Beta Was this translation helpful? Give feedback.
In order to provide non-blocking atomic operation on the queue entries, each entry must be 16 bytes or less, as the hardware atomic operations which are non-blocking are limited to 16 bytes, ( DWCAS, see below). The Queue requires 32 bits for internal entry state, which leaves the transferable data type to 12 bytes.
To use the queue with movable objects of 12 bytes or less, you can see the queue implementation that transfers std::unique_ptr<> in the header file: pointer_mpmc_queue.h - it uses the reset() and release() methods to keep a single owner to the target object.
In case you need to transfer bigger objects, you might want to use the std::unique_ptr as the transferable units.
Note: …