Skip to content

12 threads with a lock were 231x slower than 1

Youtube 0:56 113 views
ZetBit

ZetBit

@UC3zY4m_LrHraxTCv-lFPPIg

Twelve threads added one to the same counter a million times each. Without protection I got between 1.1 and 2.2 million instead of 12 million. With a lock the answer was right, but it took 705 ms, while one thread doing all 12 million additions took 3 ms. Letting each thread count on its own and adding the results at the end took 1.5 ms.

More Videos