ce • Isol a ted from others Thre a d • Lives inside a process • Sh a res memory with other thre a ds • Lightweight a nd f a st to cre a te J a v a progr a ms => one process, often m a ny thre a ds
- To h a ndle multiple clients (servers!) - To a void blocking everything while w a iting Ex a mples: - Web server h a ndling m a ny browsers - GUI th a t st a ys responsive while doing work - G a me loop + input + rendering
ckbo a rd (Singleton) th a t stores a St a ck<Integer> • Cre a te a Person cl a ss (Runn a ble) th a t continuously pushes numbers • Cre a te a C a t cl a ss (Runn a ble) th a t continuously pops numbers • St a rt a ll thre a ds from m a in • m a in periodic a lly prints the Bl a ckbo a rd contents Rules • Use a regul a r St a ck (no concurrent or blocking structures) • No synchroniz a tion a t f irst (this is intention a l) • Expect incorrect or inconsistent beh a vior
ts a nd 1 object person • Run 10 object person a nd 1 object c a ts • Wh a t h a ppens when C a ts pop from a n empty st a ck? • Does output ch a nge between runs? Why?
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. 18