class: title # Concurrency with Threads ## CSC 213 – October 13, 2025 --- # Agenda for Today 1. Department Events 2. Upcoming Work 3. Threads Discussion 4. Threads Exercise 5. Wrap Up --- # Department Events ## CS Table: Reports from MINK-WIC .indent[ Tuesday, October 14th at noon in JRC 224C ] ## CS Extra: Graduate School in CS .indent[ Thursday, October 16th at 4:15pm in Noyce 3821 Refreshments available at 4pm in the CS Commons ] *To receive 0.25% extra credit, send an email to let me know you attended no more than 48 hours after the event.* --- class: section, blue # Upcoming Work --- # Lab: Worm **Due:** Wednesday, October 15th by 11:59pm **Late Deadline:** Wednesday, October 29th by 11:59pm ## Questions **The last test program doesn't work, but my scheduler can run the worm game. What's going on?** This one has us all stumped. If the worm game works and there are no AddressSanitizer issues you probably don't need to worry about the last test case. I'll be interested to hear what's causing this if anyone figures it out. --- class: section, blue # Threads --- # Discussion: Concurrency Basics **Questions for think, pair, share:** 1. How are threads different from the tasks we are implementing in the worm lab? 2. What makes programming with threads difficult? 3. Why would we want to write programs that use threads? *Start by thinking of answers on your own. I will let you know when to start discussion.* --- # Discussion: Threads API Work with your neighbor(s) to answer the following questions about the threads API. You may find it helpful to refer to the `man` pages or the Threads API reading for today. 1. What does `pthread_create` do, and how does it use each of its parameters? What does the return value indicate? ```c int pthread_create(pthread_t *restrict thread, const pthread_attr_t *restrict attr, void *(*start_routine)(void *), void *restrict arg); ``` 2. What does `pthread_join` do, and how does it use each of its parameters? What does the return value indicate? ```c int pthread_join(pthread_t thread, void **retval); ``` --- class: section, green # Threads Exercise --- class: section, blue # Wrap Up --- # Reminders ## Lab The worm lab is due on Wednesday. Make sure the scheduler works for the worm game, including a clean exit when you crash. ## Assignment There is no assignment this week ## Need Help? My office hours are limited this week (sorry), but I can still answer questions over email and mentor sessions are available on the regular schedule. ## Reading - **Locks** (OSTEP, Chapter 28) - **Lock-based Concurrent Data Structures** (OSTEP, Chapter 29)