c a nnot be modi f ied a fter cre a tion. • Once constructed, its st a te never ch a nges. Wh a t does this p a ttern gu a r a ntee? • Thre a d s a fety by design • No synchroniz a tion required • No r a ce conditions When to Use Immut a ble Objects? • D a t a is sh a red a cross thre a ds • St a te does not need to ch a nge • Simplicity a nd s a fety a re priorities
a its (is suspended) until a gu a rd condition becomes true. • Another thre a d l a ter ch a nges the st a te a nd sign a ls the w a iting thre a d to resume. Us a ge: • A Client thre a d w a nts d a t a . • A Worker thre a d produces the d a t a l a ter. • The client w a its s a fely until the d a t a is a v a il a ble.
a te predic a te th a t thre a ds c a n w a it for while holding a lock. • E a ch Condition is tied to one speci f ic lock When a thre a d c a lls a w a it(): • It rele a ses the lock • It goes to sleep When sign a led: • It re- a cquires the lock • Execution resumes a fter a w a it()
Computing Javier Gonzalez-Sanchez, Ph.D. [email protected] Winter 2026 Copyright. These slides can only be used as study material for the class CSC 364 at Cal Poly. They cannot be distributed or used for another purpose. 25