Project Part I Background Tom Roeder CS415 2005sp.

Slides:



Advertisements
Similar presentations
Operating Systems ECE344 Midterm review Ding Yuan
Advertisements

Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Chapter 6 (a): Synchronization.
Background Concurrent access to shared data can lead to inconsistencies Maintaining data consistency among cooperating processes is critical What is wrong.
EEE 435 Principles of Operating Systems Interprocess Communication Pt II (Modern Operating Systems 2.3)
1 Operating Systems, 122 Practical Session 5, Synchronization 1.
Interprocess Communication
CS 162 Discussion Section Week 3. Who am I? Mosharaf Chowdhury Office 651 Soda 4-5PM.
CS444/CS544 Operating Systems Synchronization 2/21/2006 Prof. Searleman
CS444/CS544 Operating Systems Synchronization 2/16/2006 Prof. Searleman
CS414 Minithreads project overview
CS533 Concepts of Operating Systems Class 3 Monitors.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts Amherst Operating Systems CMPSCI 377 Lecture.
1 CSE451 – Section 4. 2 Reminders Project 2 parts 1,2,3 due next Thursday Threads, synchronization Today: Project 2 continued (parts 2,3) Synchronization.
5.6 Semaphores Semaphores –Software construct that can be used to enforce mutual exclusion –Contains a protected variable Can be accessed only via wait.
1 CS318 Project #3 Preemptive Kernel. 2 Continuing from Project 2 Project 2 involved: Context Switch Stack Manipulation Saving State Moving between threads,
5.6 Semaphores Semaphores –Software construct that can be used to enforce mutual exclusion –Contains a protected variable Can be accessed only via wait.
Semaphores. Announcements No CS 415 Section this Friday Tom Roeder will hold office hours Homework 2 is due today.
5.6.2 Thread Synchronization with Semaphores Semaphores can be used to notify other threads that events have occurred –Producer-consumer relationship Producer.
Synchronization Principles. Race Conditions Race Conditions: An Example spooler directory out in 4 7 somefile.txt list.c scores.txt Process.
Semaphores CSCI 444/544 Operating Systems Fall 2008.
Preemptive Minithreads Tom Roeder CS sp. Multi-level Feedback Queues Quantum = 2 Quantum = 4 Quantum = 8 Quantum = 16 Lowest priority Highest priority.
CS533 - Concepts of Operating Systems 1 Class Discussion.
CS414 Minithreads Project 1 Overview Adrian Bozdog (Adi)
CPS110: Implementing threads/locks on a uni-processor Landon Cox.
Race Conditions CS550 Operating Systems. Review So far, we have discussed Processes and Threads and talked about multithreading and MPI processes by example.
Threads CS 416: Operating Systems Design, Spring 2001 Department of Computer Science Rutgers University
Intro to OS CUCS Mossé Processes and Threads What is a process? What is a thread? What types? A program has one or more locus of execution. Each execution.
CS Introduction to Operating Systems
CSE 451: Operating Systems Autumn 2013 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Buffer overflows.
Nachos Phase 1 Code -Hints and Comments
Process Synchronization Continued 7.2 Critical-Section Problem 7.3 Synchronization Hardware 7.4 Semaphores.
Operating Systems Lecture 7 OS Potpourri Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of Software.
Midterm 1 – Wednesday, June 4  Chapters 1-3: understand material as it relates to concepts covered  Chapter 4 - Processes: 4.1 Process Concept 4.2 Process.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Mutual Exclusion.
Copyright ©: University of Illinois CS 241 Staff1 Threads Systems Concepts.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 9 th Edition Chapter 5: Process Synchronization.
Kernel Locking Techniques by Robert Love presented by Scott Price.
CPS110: Implementing threads Landon Cox. Recap and looking ahead Hardware OS Applications Where we’ve been Where we’re going.
1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof.
Discussion Week 2 TA: Kyle Dewey. Overview Concurrency Process level Thread level MIPS - switch.s Project #1.
Week 3 January 22, 2004 Adrienne Noble. Today CVS – a great tool to use with your groups Threads – basic thread operations Intro to synchronization Hand.
Operating Systems CSE 411 CPU Management Sept Lecture 10 Instructor: Bhuvan Urgaonkar.
CS399 New Beginnings Jonathan Walpole. 2 Concurrent Programming & Synchronization Primitives.
CSE 153 Design of Operating Systems Winter 2015 Midterm Review.
CSCI1600: Embedded and Real Time Software Lecture 17: Concurrent Programming Steven Reiss, Fall 2015.
Slides on threads borrowed by Chase Landon Cox. Thread states BlockedReady Running Thread is scheduled Thread is Pre-empted (or yields) Thread calls Lock.
Implementing Mutual Exclusion Andy Wang Operating Systems COP 4610 / CGS 5765.
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
CPS110: Implementing threads on a uni-processor Landon Cox January 29, 2008.
Process Synchronization. Concurrency Definition: Two or more processes execute concurrently when they execute different activities on different devices.
CS 6560: Operating Systems Design
CS703 – Advanced Operating Systems
Background on the need for Synchronization
Threads, Concurrency, and Parallelism
CSE 451: Operating Systems Spring 2012 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Synchronization and Semaphores
UNIVERSITY of WISCONSIN-MADISON Computer Sciences Department
CSCI1600: Embedded and Real Time Software
Implementing Mutual Exclusion
CSE 451: Operating Systems Winter Module 7 Semaphores and Monitors
CSE 153 Design of Operating Systems Winter 19
CSE 153 Design of Operating Systems Winter 2019
CS333 Intro to Operating Systems
Chapter 6: Synchronization Tools
CSCI1600: Embedded and Real Time Software
CS703 – Advanced Operating Systems
CS444/544 Operating Systems II Scheduler
Sarah Diesburg Operating Systems CS 3430
Presentation transcript:

Project Part I Background Tom Roeder CS sp

You need to implement minithreads  yield  fork/create/initialize  stop/start synchronization  P/V  create/initialize/destroy FIFO non-preemptive scheduler Test cases

Threads Each thread must have its own control block Contains  top pointer  base pointer  thread identifier  … whatever else you find useful To switch between threads, must change esp

Context Switching thread 1 call stack ESP thread 1 thread 2 call stack thread 2 ret addr 2 thread 2 registers context_switch(new, old) ??

Context Switching thread 1 call stack ESP thread 1 thread 2 call stack thread 2 ret addr 2 thread 2 registers thread 1 registers ret addr 1 context_switch(new, old)

Context Switching thread 1 call stack ESP thread 1 thread 2 call stack thread 2 ret addr 2 thread 2 registers thread 1 registers ret addr 1 context_switch(new, old)

Context Switching thread 1 call stack ESP thread 1 thread 2 call stack thread 2 thread 1 registers ret addr 1 context_switch(new, old)

Frequently Asked Questions How do I bootstrap into a minithreads environment? (a.k.a. How do I context switch into my first thread?)  Use the initial kernel thread  Wrap it in a minithread structure The stack sometimes grows downwards and sometimes up. What’s going on?  Normally grows down  We normally talk (and think) about it growing up

Frequently Asked Questions How do I clean up my thread when I’m still on its stack?  You can’t  add a garbage collection thread. What’s the difference between create and fork?  create results in a new not running thread  fork results in a new running thread

Scheduler Take the first element off the run queue and run it (FIFO) Need to have a garbage collection thread Need to have a system idle thread  see the System Idle Process in Ctl-Shift-Esc  Should run when nothing else is running When all your threads exit, your program should stay around

Software Engineering Need to check for valid values in functions  Use AbortOnCondition  Might want to define something like: #define AbortOnNull(var) AbortOnCondition(var == NULL, #var “ should not be NULL”); Use macros to your advantage Check return values of functions with AbortOnError(func_call());

Software Engineering Comments  Clear and understandable  Document why not what  We should not have to guess the code’s purpose Naming  give variables simple functional names  single letters are in general discouraged Modularization  remember to refactor every once in a while

Testing Write a test program  Create many threads  Create no threads  try our tests (test[1-3].c, sieve.c, buffer.c)  unit test your functions try unreasonable values for parameters figure out invariants and check them The key is to systematically try as many cases as possible

Testing Best to automate testing:  Have a test harness generate lots of tests  Especially ones that are easy to figure out what the right answer should be Test each other’s code in the group  When you look at code for long enough, you don’t always notice the bugs Code review  especially the tricky parts of the code

Questions?

Synchronization Recall the problem posed in 414  Operations that appear atomic to C are not always  Even in C, we often don’t want to be interrupted  Need a Do Not Disturb sign Enter locks  allow implementation of mutual exclusion  lets N threads in at a time  Everyone else must wait outside We will use semaphores for now

Synchronization: Semaphores Two operations: P (proberen) and V (verhogen)  P (test) does the following atomically: decrement the semaphore if it is less than 0, block else continue  V (increment) does the following atomically: increment the semaphore if the value of the semaphore is now greater than or equal to 0 and there is someone waiting, let them in Note that we have not solved atomicity

Synchronization: Semaphores Fortunately, there is no preemption for now  Easy to get mutual exclusion  Just don’t yield in P or V! Ranveer will explain in 414 what to do in the case of preemption  Don’t need to know this for this part of the project

Synchronization Example semaphore s; int x = 0; thread_1 () { while(true) { P(s); x = x + 10; V(s); } thread_2 () { while(true) { P(s); x = x - 10; V(s); }