multithreading - When are lock free data structures less performant than mutual exclusion (mutexes)? -


I read somewhere (can not find the page now) that locking the free data structure is more efficient for "some workloads" It seems that sometimes they are really slow or the benefits of them can be zero in some situations. To do a nuclear session, a lock instruction seems to hit ~ 100 cycles, go to sleep and take back the process. I have a lot to wait for the scheduler It seems to me that, in which case a lock-free data structure would be better than the old-fashioned mutes if 99% of the lock time is available and the process is not going to sleep, is it Is there a mute fast? Is there a good rule of thumb to go by which way to go, assuming to be a suitable lock-free data structure?

A common way to implement lock-free data structure is to have an unstable reference to an irreversible thing , And whatever you want to change to grab the structure, create a new version of the object with the appropriate changes applied to it, and then compare the index to reference the object, if the comparison expense works , So great. If not, then move the new object, grab the context again and start over again.

This can do a good job if it is cheap to produce a new object and the level of contention is quite low, compare the exchange, the exchange will usually work. If there is enough logic, and if the new object is slow, then it may take N ^ 2 to complete updates updated by N Thread. As an extreme example, suppose 100 threads are running on a CPU, an update should be 100 mm. The CPU takes the time (only one time piece), and all the 100 threads try to update the object once. During the first ten seconds, each thread will generate a new object based on the original one. One of the threads will work successfully, while others will fail. During the next 9.9 seconds, 99 threads will create new versions of the object, after which one will be successfully updated and 98 will fail. The net effect would be that in order to make 100 updates in the lock-free method, it would take 505 seconds worth of CPU time, when a locking system could do it in about 10 seconds.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -