Presentation is loading. Please wait.

Presentation is loading. Please wait.

Project #3, Threads and Synchronization CS-3013 A-term 20091 Project #3 Threads and Synchronization CS-3013, Operating Systems A-term 2009 Due Tuesday,

Similar presentations


Presentation on theme: "Project #3, Threads and Synchronization CS-3013 A-term 20091 Project #3 Threads and Synchronization CS-3013, Operating Systems A-term 2009 Due Tuesday,"— Presentation transcript:

1 Project #3, Threads and Synchronization CS-3013 A-term 20091 Project #3 Threads and Synchronization CS-3013, Operating Systems A-term 2009 Due Tuesday, September 22, 2009, 11:59 PM

2 Project #3, Threads and Synchronization CS-3013 A-term 20092 Objective To learn to use threads and synchronization mechanisms in user space To implement a multi-threaded program that aggressively pounds on a shared resource

3 Project #3, Threads and Synchronization CS-3013 A-term 20093 The Problem Model a communal bathroom used by both sexes Possible states of the bathroom:– Vacant Occupied by women Occupied by men Rules:– Anyone may enter if vacant A user may enter if occupied by same sex A user must wait until vacant if occupied by opposite sex –Any number of users may by waiting at same time.

4 Project #3, Threads and Synchronization CS-3013 A-term 20094 Implementation Control module:– A.h file and a.c file Interface:– Enum gender = {male, female}; void Enter(gender g); void Leave(void); void Initialize(...); Must correctly maintain:– State # of users in bathroom Gender of users in bathroom Waits until vacant if occupied by opposite gender Sets state to vacant if this is the last user occupying Multiple threads trying to access or change at same time!

5 Project #3, Threads and Synchronization CS-3013 A-term 20095 Multi-threaded Test Program main() function is master thread –Interprets argc and argv –Spawns n user threads Randomly sets gender, loop count of each user thread Specifies arrival time and stay time –Mean and standard deviation –Waits for user threads to finish –Prints summary –Exits cleanly With no outstanding user threads!

6 Project #3, Threads and Synchronization CS-3013 A-term 20096 User Thread Loops loop count times For each iteration:– Generate random arrival and stay times Sleep arrival units of time Invoke Enter(gender) –May wait a long time if occupied by opposite gender Sleep stay units of time Invoke Leave() Collect statistics Print statistics (min, max, average wait time to enter) Exit cleanly So that master thread knows that user thread is done

7 Project #3, Threads and Synchronization CS-3013 A-term 20097 As Simple as That! With a few minor challenges!

8 Project #3, Threads and Synchronization CS-3013 A-term 20098 Synchronization Challenges Shared database representing state of bathroom, count, etc. Mutex for protecting shared access Semaphore or condition variable for waiting Clean exit from user thread pthread_join or barrier synchronization & detach Printing to stdout from multiple threads Without getting mixed up.

9 Project #3, Threads and Synchronization CS-3013 A-term 20099 Other Challenges Random number generation Around a mean; use “standard deviation” for width Optional (extra credit) Poisson distribution for arrivals Gaussian distribution for stay times Simulating units of time #include Suggest 10 or 100 milliseconds for one time unit.

10 Project #3, Threads and Synchronization CS-3013 A-term 200910 Write-up Explain invariant of shared data structure Show Enter() and Leave() preserve invariant Or show states & state transition diagram Explain master thread and user thread relationship Creation and termination

11 Project #3, Threads and Synchronization CS-3013 A-term 200911 Individual and Class Project Suggest you define Common command line format Common.h file for control module May discuss algorithms, strategies, etc. May help each other test programs Write individual code Own style, own words, own documentation, etc.

12 Project #3, Threads and Synchronization CS-3013 A-term 200912 Due Date Project due on Tuesday, September 22, at 11:59 PM Submit via web-based Turnin Project 3 Report to instructor or TAs any difficulties

13 Project #3, Threads and Synchronization CS-3013 A-term 200913 Questions?


Download ppt "Project #3, Threads and Synchronization CS-3013 A-term 20091 Project #3 Threads and Synchronization CS-3013, Operating Systems A-term 2009 Due Tuesday,"

Similar presentations


Ads by Google