Project 3 Threads and Synchronization

Slides:



Advertisements
Similar presentations
Operating Systems Semaphores II
Advertisements

Pointers.
Linked Lists CSE 2451 Matt Boggus. Dynamic memory reminder Allocate memory during run-time malloc() and calloc() – return a void pointer to memory or.
Data Structure Lecture-5
Operating Systems Lecture 7.
Ch 7 B.
Data Structures Lecture 13: QUEUES Azhar Maqsood NUST Institute of Information Technology (NIIT)
C Intro.
Event-drive SimulationCS-2303, C-Term Project #3 – Event-driven Simulation CS-2303 System Programming Concepts (Slides include materials from The.
By: Gal Nave and Dan Slov Supervisor: Dmitri Perelman Technion, Electrical engineering department NSSL Laboratory.
CS 3013 & CS 502 Summer 2006 Digressions:– Producer-Consumer and Stacks 1 Two Digressions Stacks Producer-Consumer models.
Project #3, Threads and Synchronization CS-3013 A-term Project #3 Threads and Synchronization CS-3013, Operating Systems A-term 2009 Due Tuesday,
Concurrency 1 CS502 Spring 2006 Thought experiment static int y = 0; int main(int argc, char **argv) { extern int y; y = y + 1; return 0; }
Introduction to Processes CS Intoduction to Operating Systems.
CY2003 Computer Systems Lecture 06 Interprocess Communication Monitors.
Lists 1. Introduction Data: A finite sequence of data items. Operations: Construction: Create an empty list Empty: Check if list is empty Insert: Add.
Design of Bio-Medical Virtual Instrumentation Tutorial 2.
POSIX Synchronization Introduction to Operating Systems: Discussion Module 5.
APS105 Lists. Structures Arrays allow a collection of elements –All of the same type How to collect elements of different types? –Structures; in C: struct.
12/22/ Thread Model for Realizing Concurrency B. Ramamurthy.
CNG 140 C Programming (Lecture set 12) Spring Chapter 13 Dynamic Data Structures.
CS 151: Object-Oriented Design November 26 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
7/9/ Realizing Concurrency using Posix Threads (pthreads) B. Ramamurthy.
Case Study: Pthread Synchronization Dr. Yingwu Zhu.
Introduction to Operating Systems
Winter 2009 Tutorial #6 Arrays Part 2, Structures, Debugger
Linked List :: Basic Concepts
Lectures linked lists Chapter 6 of textbook
Lesson One – Creating a thread
PThreads.
Doubly Linked List Review - We are writing this code
Data Structures and Algorithms
Copyright ©: Nahrstedt, Angrave, Abdelzaher
CS399 New Beginnings Jonathan Walpole.
Lecture 25 More Synchronized Data and Producer/Consumer Relationship
Principles of Operating Systems Lecture 8
AMIKaya Phase 1 Project Specifications
CS510 Operating System Foundations
CS510 Operating System Foundations
Outline for this evening
Lists.
Programmazione I a.a. 2017/2018.
Prof. Neary Adapted from slides by Dr. Katherine Gibson
Lists.
Circular Buffers, Linked Lists
Introduction to Operating Systems
Realizing Concurrency using Posix Threads (pthreads)
Operating Systems Lecture 13.
Synchronization Lecture 23 – Fall 2017.
Recitation 14: Proxy Lab Part 2
COP 4600 Operating Systems Spring 2011
Cancellation.
PTHREADS AND SEMAPHORES
Race Conditions & Synchronization
CS510 Operating System Foundations
Jonathan Walpole Computer Science Portland State University
Today’s agenda Lab 1 Module 4: Process Management
Data Structures and Algorithms
Programming Fundamentals Lecture #3 Overview of Computer Programming
Processes and Process Management
Project #3 Threads and Synchronization
Realizing Concurrency using Posix Threads (pthreads)
Chapter 6 Synchronization Principles
CS5123 Software Validation and Quality Assurance
Realizing Concurrency using Posix Threads (pthreads)
Processes in Unix, Linux, and Windows
CSE 153 Design of Operating Systems Winter 2019
CSE 451 Section 1/27/2000.
EECE.4810/EECE.5730 Operating Systems
Module 13 Dynamic Memory.
Presentation transcript:

Project 3 Threads and Synchronization Due Thursday, September 25, 6:00 PM Assumptions: Graduate level Operating Systems Making Choices about operation systems Why a micro-century? …just about enough time for one concept CS-3013 A-term 2008 Project 3, Threads and Synchronization

Project 3, Threads and Synchronization Purpose To introduce you to working with threads and synchronization operations To prepare for Project 4 CS-3013 A-term 2008 Project 3, Threads and Synchronization

Project 3, Threads and Synchronization Approach Implement a simple, shared data structure I.e., a doubly-linked list, like the one in previous lecture notes Shared access and updating by multiple threads Implement a multi-threaded test program To exercise the shared data structure, accessing, and updating CS-3013 A-term 2008 Project 3, Threads and Synchronization

Project 3, Threads and Synchronization Shared Data Structure struct Item { struct Item *next, *prev; pthread_t creating_thread; struct timespec time_added: }; extern struct Item *head, *tail; #define MAX_ITEMS 128 See project3.h CS-3013 A-term 2008 Project 3, Threads and Synchronization

Operations on Shared Data Structure int AddItem(int block); Int RemoveItem(pthread_t *threadID, timespec *time_added, int block); #define BLOCK 1 #define NO_BLOCK 0 CS-3013 A-term 2008 Project 3, Threads and Synchronization

Project 3, Threads and Synchronization Operational Details AddItem(int block) If list is not full Creates new Item using malloc() Adds ID of current thread and also current time Links onto end of list pointed to by *head, *tail Returns zero If list is full and block = BLOCK Blocks and waits until someone removes an item from list, and then proceeds as above. If list is full and block = NO_BLOCK Returns immediately with error code. No item added to list; any malloc() is undone CS-3013 A-term 2008 Project 3, Threads and Synchronization

Operational Details (continued) Int RemoveItem(pthread_t *threadID, timespec *time_added, int block); If list is not empty Removes Item from list, extracts threadID and time_added Calls free() to release storage for Item Returns zero If list is empty and block = BLOCK Blocks and waits until someone adds an item to list, and then proceeds as above. If list is full and block = NO_BLOCK Returns immediately with error code. No item removed from list; no free() executed CS-3013 A-term 2008 Project 3, Threads and Synchronization

Project 3, Threads and Synchronization Implementation AddItem, RemoveItem, head, and tail implemented in Project3.c Implementation must be thread-safe Need to provide synchronization among competing threads Monitor style Producer-Consumer style Any other style you can document and explain! CS-3013 A-term 2008 Project 3, Threads and Synchronization

Project 3, Threads and Synchronization Test Program Multi-threaded Master (i.e. main()) creates worker threads Some execute AddItem() Some execute RemoveItem() # of worker threads and duration of test specified in command line After duration seconds have elapsed, master orders worker threads to stop CS-3013 A-term 2008 Project 3, Threads and Synchronization

Test Program (continued) Each worker thread Checks for “stop” condition If none, waits random # of milliseconds Executes AddItem or RemoveItem (according to type of thread) block = BLOCK Loops If “stop” condition “Adding” threads exit immediately with # of items added in status “Removing” threads continue to loop with block = NO_BLOCK to clear out list, then exit with # of items removed in status CS-3013 A-term 2008 Project 3, Threads and Synchronization

Test Program (continued) After ordering “stop”, master waits for each thread to exit via pthread_join() Collects total numbers of items added or deleted by each thread Prints summary message Exits CS-3013 A-term 2008 Project 3, Threads and Synchronization

Project 3, Threads and Synchronization Issues Master must provide for threads that are blocked after stop is ordered E.g., add new items so threads can unblock Memory leaks Be alert for possibility that some items were malloc’d but not free’d Check your code; use printf() for debugging Deadlocks Incorrect synchronization typically causes test program threads to deadlock CS-3013 A-term 2008 Project 3, Threads and Synchronization

Project 3, Threads and Synchronization Write-up Bigger, more comprehensive than most project write-ups Explain synchronization Specify program invariants sufficient to explain behavior of program Show how AddItem and RemoveItem preserve invariants Prove (or cogently explain) why items are removed in order added CS-3013 A-term 2008 Project 3, Threads and Synchronization

Project 3, Threads and Synchronization Grading 1 pt:– make without warnings or errors 5 pts: correctly execute your test cases without memory leaks n adding threads, m removing threads, duration d seconds 5 pts: correctly execute grader’s test cases without memory leaks 4 pts: code review by grader 5 pts: write-up CS-3013 A-term 2008 Project 3, Threads and Synchronization

Project 3, Threads and Synchronization Questions? CS-3013 A-term 2008 Project 3, Threads and Synchronization