I implemented a lock-free queue with the GCC __sync_xxx_compare_and_swap
atomic builtin. Now I want to make sure that my code is correct. So I started multiple threads for enqueueing and dequeueing, and tried to:
- measure the number of enqueue and dequeue operations, and check if they match
- measure the number of times an individual element is enqueued and dequeued, and check if that number for each element is two (1 enqueueing and 1 dequeueing)
I found that the above two results are correct, but how can I verify that the enqueueing order is exactly the same as the dequeueing order? Or, is there any way to check the correctness of my implementation?