Mutual Exclusion and Memory Models

What We Learned in Day 1

        We covered how to create threads and use the intrinsic locks built into every

Java object to enforce mutual exclusion between them. We also saw the three

primary perils of threads and locks—race conditions, deadlock, and memory

visibility, and we discussed some rules that help us avoid them:

 Synchronize all access to shared variables.

 Both the writing and the reading threads need to use synchronization.

 Acquire multiple locks in a fixed, global order.

 Don’t call alien methods while holding a lock.

 Hold locks for the shortest possible amount of time.


你可能感兴趣的:(memory,and,models,exclusion,Mutual)