1 CSE451 Section 3. 2 Reminders Start project 2! It’s long Read the assignment carefully Read it again Project 2 will be done in groups of 3 Today: Form.

Slides:



Advertisements
Similar presentations
Utilizing the GDB debugger to analyze programs Background and application.
Advertisements

Day 10 Threads. Threads and Processes  Process is seen as two entities Unit of resource allocation (process or task) Unit of dispatch or scheduling (thread.
CSE 451: Operating Systems Section 6 Project 2b; Midterm Review.
CSE 451: Operating Systems
1 Processes and Pipes COS 217 Professor Jennifer Rexford.
CSE451 Section 3: Winter 2k7 Welcome to the world of concurrency! Kurtis Aaron Kimball
1 Reminders Start project 2! It’s long Read the assignment carefully Read it again Project 2 will be done in groups of 3 groups to me Part 1 due.
1 Reminders Start project 2! It’s long Read the assignment carefully Read it again Make sure your groups are correct Today: Project 2 intro CVS.
Threads CSCI 444/544 Operating Systems Fall 2008.
CS-502 Fall 2006Processes in Unix, Linux, & Windows 1 Processes in Unix, Linux, and Windows CS502 Operating Systems.
Low level CASE: Source Code Management. Source Code Management  Also known as Configuration Management  Source Code Managers are tools that: –Archive.
CS414 Minithreads Project 1 Overview Adrian Bozdog (Adi)
CPS110: Implementing threads/locks on a uni-processor Landon Cox.
Threads CS 416: Operating Systems Design, Spring 2001 Department of Computer Science Rutgers University
1 Threads Chapter 4 Reading: 4.1,4.4, Process Characteristics l Unit of resource ownership - process is allocated: n a virtual address space to.
Processes in Unix, Linux, and Windows CS-502 Fall Processes in Unix, Linux, and Windows CS502 Operating Systems (Slides include materials from Operating.
Stacks and Frames Demystified CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.
Git for Version Control These slides are heavily based on slides created by Ruth Anderson for CSE 390a. Thanks, Ruth! images taken from
Subversion. What is Subversion? A Version Control System A successor to CVS and SourceSafe Essentially gives you a tracked, shared file system.
Welcome to the World of Nachos CPS 110 Spring 2004 Discussion Session 1.
Introduction to Threads CS240 Programming in C. Introduction to Threads A thread is a path execution By default, a C/C++ program has one thread called.
Chapter 1 Process and Thread. 1.2 process The address space of a program – Text – Code – Stack – Heap A set of registers – PC – SP Other resources – Files.
An Intro to Concurrent Versions System (CVS) ECE 417/617: Elements of Software Engineering Stan Birchfield Clemson University.
CVS – concurrent versions system Network Management Workshop intERlab at AIT Thailand March 11-15, 2008.
CSE 219 Computer Science III CVS
CS333 Intro to Operating Systems Jonathan Walpole.
CVS – concurrent versions system AROC Guatemala July 19-23, 2010 Guatemala City, Guatemala.
CPS110: Implementing threads Landon Cox. Recap and looking ahead Hardware OS Applications Where we’ve been Where we’re going.
1 CSE306 Operating Systems Projects CVS/SSH tutorial.
Multi-Tasking The Multi-Tasking service is offered by VxWorks with its real- time kernel “WIND”.
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.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Processes and Threads.
12 CVS Mauro Jaskelioff (originally by Gail Hopkins)
Version Control System
CSE 451: Operating Systems Section 4 Scheduling, Project 2 Intro, Threads.
NachOS Threads System Road Map through the Code Lab 3.
Recitation 2: Abhijit Warkhedi2/25/20161 Today’s Agenda u CVS u GDB.
Slides on threads borrowed by Chase Landon Cox. Thread states BlockedReady Running Thread is scheduled Thread is Pre-empted (or yields) Thread calls Lock.
CSE 451: Operating Systems Section 6 Project 2b. Midterm  Scores will be on Catalyst and midterms were handed back on Friday(?) in class  Talk to Ed,
CPS110: Implementing threads on a uni-processor Landon Cox January 29, 2008.
Using Subversion for Source Code Control Michael McLennan HUBzero® Platform for Scientific Collaboration Purdue University This work licensed under Creative.
1 Subversion Kate Hedstrom April Version Control Software System for managing source files –For groups of people working on the same code –When.
CSE 451: Operating Systems Section 4 Project 2 Intro; Threads.
7/9/ Realizing Concurrency using Posix Threads (pthreads) B. Ramamurthy.
Process Tables; Threads
CVS – concurrent versions system
CVS – concurrent versions system
CSE 451 Section 4 Project 1 Notes Looking ahead: Project 2.
CS 6560: Operating Systems Design
Processes.
Scheduler activations
CS399 New Beginnings Jonathan Walpole.
Threading and Project 2 (Some slides taken from Sec. 3 Winter 2006)
Threads & multithreading
Reminders Form groups of 3 by tomorrow Start project 2! Today:
Processes in Unix, Linux, and Windows
Process Tables; Threads
CSE451 – Section 6.
CVS Concurrent Versioning System
CSE 153 Design of Operating Systems Winter 2018
Lecture Topics: 11/1 General Operating System Concepts Processes
CSE 451 Autumn 2003 Section 3 October 16.
Threads Chapter 5 2/17/2019 B.Ramamurthy.
Threads Chapter 5 2/23/2019 B.Ramamurthy.
CSE 153 Design of Operating Systems Winter 2019
CS703 – Advanced Operating Systems
Welcome to the world of concurrency!
Presentation transcript:

1 CSE451 Section 3

2 Reminders Start project 2! It’s long Read the assignment carefully Read it again Project 2 will be done in groups of 3 Today: Form project 2 groups Project 2 intro CVS

3 Project 2 You have to: Implement a user thread library Implement synchronization primitives Solve a synchronization problem Add Preemption Implement a multithreaded web server Get some results and write a (small) report Part a due: in two weeks (Thurs, April 28 12:00pm) Part b due: 11 days after part a (Monday, May 9 12:00pm) Part a Part b

4 Simplethreads We give you: Skeleton functions for thread interface Machine-specific code Support for creating new stacks Support for saving regs/switching stacks A generic queue When do you need one? Very simple test programs You should write more Singlethreaded web server

5 Simplethreads Code Structure include/sthread.h Other appsWeb server (web/sioux.c) test/*.c lib/sthread_user.h lib/sthread_user.c lib/sthread_ctx.c lib/sthread_ctx.h You write this sthread_switch_i386.h sthread_switch_powerpc.h lib/sthread_switch.S lib/sthread_queue.c lib/sthread_queue.h lib/sthread_preempt.c lib/sthread_preempt.h

6 Thread Operations void sthread_init() Initialize the whole system sthread_t sthread_create(func start_func, void *arg) Create a new thread and make it runnable void sthread_yield() Give up the CPU void sthread_exit(void *ret) Exit current thread What about the TCB? struct _thread { sthread_ctx_t *saved_ctx; ……… } Others?

7 Sample multithreaded program int main(int argc, char **argv) { int i; sthread_init(); if (sthread_create(thread_start, (void*)i) == NULL) { printf("sthread_create failed\n"); exit(1); } sthread_yield(); //yield main thread to our new thread printf("back in main\n"); return 0; } void *thread_start(void *arg) { printf("In thread_start, arg = %d\n", (int)arg); return 0; } Output? (assume no preemption)

8 Managing Contexts (given) Thread context = thread stack + stack pointer sthread_new_ctx(func_to_run) gives a new thread context that can be switched to sthread_free_ctx(some_old_ctx) Deletes the supplied context  sthread_switch(oldctx, newctx) Puts current context into oldctx Takes newctx and makes it current

9 How sthread_switch works Xsthread_switch: pusha movl %esp,(%eax) movl %edx,%esp popa ret Thread 1 TCB … SP Thread 2 TCB … SP ESP CPU Thread 1 runningThread 2 ready Want to switch to thread 2… Thread 2 registers Thread 1 regs

10 Push old context Xsthread_switch: pusha movl %esp,(%eax) movl %edx,%esp popa ret Thread 1 TCB … SP Thread 2 TCB … SP ESP CPU Thread 1 runningThread 2 ready Thread 2 registers Thread 1 registers Thread 1 regs

11 Save old stack pointer Xsthread_switch: pusha movl %esp,(%eax) movl %edx,%esp popa ret Thread 1 TCB … SP Thread 2 TCB … SP ESP CPU Thread 1 runningThread 2 ready Thread 2 registers Thread 1 registers Thread 1 regs

12 Change stack pointers Xsthread_switch: pusha movl %esp,(%eax) movl %edx,%esp popa ret Thread 1 TCB … SP Thread 2 TCB … SP ESP CPU Thread 1 readyThread 2 running Thread 2 registers Thread 1 registers Thread 1 regs

13 Pop off new context Xsthread_switch: pusha movl %esp,(%eax) movl %edx,%esp popa ret Thread 1 TCB … SP Thread 2 TCB … SP ESP CPU Thread 1 readyThread 2 running Thread 1 registers Thread 2 regs

14 Done; return Xsthread_switch: pusha movl %esp,(%eax) movl %edx,%esp popa ret Thread 1 TCB … SP Thread 2 TCB … SP ESP CPU Thread 1 readyThread 2 running Thread 1 registers What got switched? SP PC (how?) Other registers Thread 2 regs

Adjusting the PC Thread 1 TCB … SP Thread 2 TCB … SP ESP CPU Thread 2 running: switch(t2,...); 0x800:printf(“test 2”); Thread 1 registers ret pops off the new return address! ra=0x800 PC Thread 1 (stopped): switch(t1,t2); 0x400: printf(“test 1”); ra=0x400

16 Things to think about Who will call sthread_switch? Where does sthread_switch return? How do we delete a thread? Can a thread free its stack itself? Starting up a thread When you create a new stack with sthread_new_ctx(), you initialize it to run some function foo sthread_new_ctx doesn’t pass parameters to foo But in sthread_create, you give a function and an arg! Bottom line: how do you pass arguments to a function with no arguments?

17 Preemption Initially, you will build a non-preemptive thread library. In part 4, you add preemption Much more realistic model We give you: 1.Timer interrupts 2.Primitives to enable/disable interrupts 3.atomic_test_and_set/atomic_clear for synchronization You must: Do something on each timer interrupt. (What?) Synchronize all of your code using 2 and 3 above. More on this later…

18 Last note You can compare your implementation against pthreads (which is preemptive kernel-threads)../configure --with-pthreads

19 What is CVS Version control system for source files Multiple users can work on the same file simultaneously

20 Why use CVS The other way: Keep every version of code, all with different names: Project2good Project2_10_13_04 Project2working Project2_Feb_2_alex Project2_old Send s back and forth with new changes Merge different versions by hand The CVS way: One version, saved in the CVS repository Multiple people can work on the same file concurrently CVS merges the edited versions automatically as you put them back in the repository

21 Setting up CVS Set up CVS root environment var Tells CVS where to find your repository setenv CVSROOT /cse451/yourgroup/cvs (bash) export CVSROOT=/cse451/yourgroup/cvs Initialize a repository (only one person per group) Create a dir in your group’s dir to hold repository (master copy of code) cd /cse451/yourgroup mkdir cvs Initialize repository cvs init You now have an empty repository

22 Setting up CVS (2) Add/Import the simplethreads distribution to your repository tar xvfz simplethreads-1.20.tar.gz cd simplethreads-1.20 cvs import –m “initial code” simplethreads SIMPLETHREADS SIMPLETHREADS_1_20 cd.. rm –fr simplethreads-1.20

23 CVS Commands Check out a project (sandbox, or local copy) to your home directory to work on: CVS creates a dir simplethreads/ and puts copy of all source files in repository into that dir Also adds CVS dir where it stores data about what you check out cd ~ cvs checkout simplethreads cd simplethreads Merge in new changes from repository (update): cvs update [files…] Save your edited files into the repository so others can use them: cvs commit –m “fixed annoying bugs” [files…]

24 CVS Commands 2 Add a new file (source files.c or.h) to the repository cvs add [files…] Check status of a file cvs status file.c Check differences between your file and one in the repository: cvs diff file.c cvs diff –r 1.1 file.c (specifies version) View log of changes for a file cvs log file.c Use emacs for cvs commit log editing (default is vi): setenv VISUAL emacs More info: cvs --help-commands

25 CVS Remote Access Access CVS from another machine besides spinlock/coredump?: setenv CVSROOT coredump.cs.washington.edu:/cse451/yourgroup/cvs setenv CVS_RSH ssh (for CVS to know how to access repository – use ssh) (add to ~/.login (csh) or ~/.profile (bash) to avoid typing…) Warning: be wary of CVS on windows, OS X is ok