What is meant by “fast-path” uncontended synchronization?

前端 未结 3 834
清歌不尽
清歌不尽 2021-02-14 05:18

From the Performance and Scalability chapter of the JCIP book:

The synchronized mechanism is optimized for the uncontended case(volatile is alw

3条回答
  •  遇见更好的自我
    2021-02-14 05:49

    I'm not familiar with the topic of the book, but in general a “fast path” is a specific possible control flow branch which is significantly more efficient than the others and therefore preferred, but cannot handle complex cases.

    I assume that the book is talking about Java's synchronized block/qualifier. In this case, the fast path is most likely one where it is easy to detect that there are no other threads accessing the same data. What the book is saying, then, is that the implementation of synchronized has been optimized to have the best performance in the case where only one thread is actually using the object, as opposed to the case where multiple threads are and the synchronization must actually mediate among them.

提交回复
热议问题