InterlockedPushEntrySList's Performance

323 views Asked by At

I'm Testing WinAPI InterlockedPushEntrySList but my test result is a little weird.

I thought basically in LockFree, push speed will be faster as thread increase. because one thread will success push at least. in my test as thread increase InterlockedPushEntrySList's speed slower.

my test was very simple. just perform push behavior in multithread. I eliminated all another factor that caused miss test.

thread 1 : 138,075,326 thread 2 : 131,584,007 thread 3 : 90,196,884 therea 4 : 82,699,521

It's count of push for 5 seconds

plz tell me why.ㅠ did Nobody test this?

1

There are 1 answers

5
David Haim On

I thought basically in LockFree, push speed will be faster as thread increase.

If that was the case, we would all write lock free code and launch thousands of threads having infinite speed, isn't it?

"Lock-Free" just means the algorithm will not use a lock to achieve synchronization, but use atomic operations instead (most prominent a CAS loop).

It doesn't mean that a lock free algorithm will run faster than a non-lock free algorithm (it usually does).

It doesn't mean that lock free will be slower or faster depending on the number of threads (it usually becomes slower as the thread count increase)

In your case, as there are more threads, they will have to "fight" harder to get their operation to succeed, this is usually the case in multi-threaded code. the more you share between threads and the more they exists - the contention will hurt your performance. lock-free may ease the problem, but not solve it