Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CSC364 Lecture 06

CSC364 Lecture 06

Introduction to Networked, Distributed, and Parallel Computing
Threads
(202601)

Avatar for Javier Gonzalez-Sanchez

Javier Gonzalez-Sanchez PRO

January 25, 2026
Tweet

Transcript

  1. Dr. Javier Gonzalez-Sanchez [email protected] www.javiergs.info o ffi ce: 14 -227

    CSC 364 Introduction to Networked, Distributed, and Parallel Computing Lecture 06. Threads 1
  2. 3 De f inition Process • Own memory sp a

    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
  3. 4 Why Threads? - To keep progr a ms responsive

    - 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
  4. 16 Lab • Implement a sh a red Bl a

    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
  5. 17 Observe & Document • Run 10 object c a

    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?
  6. CSC 364 Introduction to Introduction to Networked, Distributed, and Parallel

    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