Semaphores in Plan 9

Total Page:16

File Type:pdf, Size:1020Kb

Semaphores in Plan 9 Semaphores in Plan 9 Sape Mullender *All L=>oH=JoHEAI &)nJMAHF,*AlCEKm Russ Cox* M16+5)1L +=m>HE@CA,M=II=?DKIAJJI !' 1. Introduction 5Am=FDoHAI =HA noM moHA JD=n " OA=HI ol@. -@ICAH 9.,EjkIJH= @AI?HE>A@ JDAm En -9, %" [,EjkIJH=, '$# En ,KJ?D]. ) IAm=FDoHA EI = non-nAC=JELA EnJACAH MEJD JMo oFAH=JEonI on EJ, P =n@ V. 6DA oHECEn oB JDA n=mAI P =n@ V EI Kn?lA=H. 1n -9, %", ,Ejk­ IJH= ?=llI IAm=FDoHAI seinpalen ,KJ?D BoH IECn=llEnC FoIJI =n@ =IIo?E=JAI V MEJD verhoog En?HAmAnJ/En?HA=IA =n@ P MEJD prolaag, = non-MoH@ HAIAm>lEnC verlaag @A?HAmAnJ/@A?HA=IA. 0A ?onJEnKAI, ‘‘Opm. 2. Vele seinpalen nemen slechts de waarden 0 en 1 aan. In dat geval fungeert de V−operatie als ‘baanvak vrijgeven’; de P− operatie, de tentatieve passering, kan slechts voltooid worden, als de betrokken seinpaal (of seinpalen) op veilig staat en passering impliceert dan een op onveilig zetten.’’ ߢߢ4Am=Hk . M=nO IECn=lI =IIKmA onlO JDA L=lKAI =n@ . 1n JD=J ?=IA JDA 8-oFAH=JEon BKn?JEonI =I ߢHAlA=IA >lo?kߣ; JDA 2-oFAH=JEon, JDA JAnJ=JELA F=IIEnC, ?=n onlO >A ?omFlAJA@, EB JDA IECn=l oH IECn=lI EnLolLA@ En@E?=JAI ?lA=H, =n@ F=IIEnC JDAn EmFlEAI IAJJEnC EJ Jo IJoF.ߣߣ 6DKI, EJ m=O >A JD=J P =n@ V MAHA EnIFEHA@ >O JDA H=ElM=O JAHmI passeer F=II=n@ verlaat lA=LA. 9A @EI?=H@ JDA H=ElM=O JAHmEnoloCO =n@ KIA JDA l=nCK=CA oB lo?kI: P EI semacquire =n@ V EI semrelease. 6DA + @A?l=H=JEonI=HA: int semacquire(long *addr, int block); long semrelease(long *addr, long count); Semacquire M=EJI BoH JDA IAm=FDoHA L=lKA *addr Jo >A?omA FoIEJELA =n@ JDAn @A?HA­ mAnJI EJ, HAJKHnEnC ; EB JDA block Bl=C EI zAHo, semacquire HAJKHnI H=JDAH JD=n M=EJ. 1B semacquire EI EnJAHHKFJA@, EJ HAJKHnI ߝ. Semrelease En?HAmAnJI JDA IAm=FDoHA L=lKA >O JDA IFA?EBEA@?oKnJ. 2l=n ' [2EkA AJ =l., ''#] D=I JH=@EJEon=llO KIA@ = @EBBAHAnJ IOn?DHonEz=JEon mA?D=­ nEIm, ?=llA@ HAn@AzLoKI. 4An@AzLoKI EI = IOmmAJHE? mA?D=nEIm; JD=J EI, EJ @oAI noJ =IIECn @EBBAHAnJ HolAI Jo JDA JMo FHo?AIIAI EnLolLA@. 6DA BEHIJ FHo?AII Jo ?=ll HAn­ @AzLoKI MEll >lo?k KnJEl JDA IA?on@ @oAI. 1n ?onJH=IJ, IAm=FDoHAI =HA =n =IOmmAJHE? mA?D=nEIm: JDA FHo?AII ANA?KJEnC semacquire ?=n >lo?k >KJ JDA FHo?AII ANA?KJEnC __________________ * NoM =J /ooClA, MoKnJ=En 8EAM, +=lEBoHnE= '""! semrelease EI CK=H=nJAA@ noJ Jo. 9A =@@A@ IAm=FDoHAI Jo 2l=n ' Jo FHoLE@A = M=O BoH = HA=l-JEmA FHo?AII Jo M=kA KF =noJDAH FHo?AII MEJDoKJ HKnnEnC JDA HEIk oB >lo?kEnC. 5En?A JDAn,MA D=LA =lIoKIA@IAm=FDoHAIBoHABBE?EAnJ FHo?AIIM=kAKF=n@lo?kEnC. 2. Hardware primitives 6DA EmFlAmAnJ=JEonI En JDEI F=FAH =IIKmA D=H@M=HA IKFFoHJ BoH =JomE? HA=@-mo@EBO- MHEJA oFAH=JEonI on = IEnClA mAmoHO lo?=JEon. 6DA BKn@=mAnJ=l oFAH=JEon EI ߢߢ?omF=HA =n@IM=F,ߣߣ MDE?D>AD=LAIlEkA JDEI+ BKn?JEon cas,>KJ ANA?KJAI=JomE?=llO: int cas(long *addr, long old, long new) { /* Executes atomically. */ if(*addr != old) return 0; *addr = new; return 1; } 1n onA =JomE? oFAH=JEon, cas ?DA?kI MDAJDAH JDA L=lKA *addr EI AGK=l Jo old =n@, EB Io, ?D=nCAIEJ Jo new. 1J HAJKHnI= Bl=CJAllEnCMDAJDAHEJ ?D=nCA@ *addr. OB ?oKHIA, cas EI noJ EmFlAmAnJA@ En +. 1nIJA=@, MA mKIJ EmFlAmAnJ EJ KIEnC IFA­ ?E=l D=H@M=HA EnIJHK?JEonI. )ll mo@AHn FHo?AIIoHI FHoLE@A = M=O Jo EmFlAmAnJ ?omF=HA =n@ IM=F. 6DA N&$ =H?DEJA?JKHA IEn?A JDA "&$ FHoLE@AI = @EHA?J ?omF=HA =n@ IM=F EnIJHK?JEon, +M2:+0/. OJDAH FHo?AIIoHIߞEn?lK@EnC JDA )lFD=, )4M, M125, =n@ 2oMAH2+ߞFHoLE@A = F=EH oB EnIJHK?JEonI ?=llA@ lo=@ lEnkA@ LL =n@ IJoHA ?on@EJEon=l 5+. 6DA LL EnIJHK?JEon HA=@I BHom = mAmoHO lo?=JEon, =n@ 5+ MHEJAI Jo = mAmoHO lo?=JEon onlO EB EJ M=I JDA mAmoHO lo?=JEon KIA@ En JDA l=IJ LL EnIJHK?JEon, =n@ JD=J lo?=JEon D=I noJ >AAn ?D=nCA@ IEn?A JDA LL. On JDoIA IOIJAmI, ?omF=HA =n@ IM=F ?=n >A EmFlA­ mAnJA@EnJAHmIoB LL =n@ 5+. 6DA EmFlAmAnJ=JEonI =lIo KIA =n =JomE? =@@EJEon oFAH=JEon xadd JD=J =JomE?=llO =@@I Jo = L=lKA En mAmoHO, HAJKHnEnC JDA nAM L=lKA. 9A @onߣJ nAA@ =@@EJEon=l D=H@M=HA IKFFoHJ BoH xadd,IEn?A EJ ?=n>A EmFlAmAnJA@KIEnC cas: long xadd(long *addr, long delta) { long v; for(;;){ v = *addr; if(cas(addr, v, v+delta)) return v+delta; } } 3. User−space semaphores 9A EmFlAmAnJA@ semacquire =n@ semrelease =I kAHnAl-FHoLE@A@ IOIJAm ?=llI. .oH ABBE?EAn?O, EJ EI KIABKl Jo D=LA = IAm=FDoHA EmFlAmAnJ=JEon JD=J, EB JDAHA EI no ?on­ JAnJEon, ?=n HKn AnJEHAlO En KIAH IF=?A, onlO B=llEnC >=?k on JDA kAHnAl Jo D=n@lA ?on­ JAnJEon. .ECKHA CELAI JDA EmFlAmAnJ=JEon. 6DA KIAH IF=?A IAm=FDoHA, = Usem, ?on­ IEIJIoB = KIAH-lALAl IAm=FDoHA L=lKA u =n@= kAHnAl L=lKA k: typedef struct Usem Usem; struct Usem { long u; long k; }; 9DAn u EI non-nAC=JELA, EJ HAFHAIAnJI JDA =?JK=l IAm=FDoHA L=lKA. 9DAn u EI nAC=JELA, JDA IAm=FDoHA D=I L=lKA zAHo: =?GKEHAHI mKIJ M=EJ on JDA kAHnAl IAm=FDoHA k =n@ HAlA=IAHImKIJ M=kA JDAmKF. void usemacquire(Usem *s) { if(xadd(&s−>u, −1) < 0) while(semacquire(&s−>k, 1) < 0){ /* Interrupted, retry */ } } void usemrelease(Usem *s) { if(xadd(&s−>u, 1) <= 0) semrelease(&s−>k, 1); } 1B JDA IAm=FDoHA EI Kn?onJAn@A@, JDA xadd En usemacquire MEll HAJKHn = non-nAC=JELA L=lKA, =LoE@EnC JDA kAHnAl ?=ll. 5EmEl=HlO, JDA xadd En usemrelease MEll HAJKHn = FoIEJELA L=lKA,=lIo=LoE@EnCJDA kAHnAl ?=ll. 4. Thread Scheduling 1n JDA 2l=n ' JDHA=@ lE>H=HO, = FHoCH=m EI m=@A KF oB = ?ollA?JEon oB FHo?AIIAI ID=HEnC mAmoHO. ) JDHA=@ EI = ?oHoKJEnA =IIECnA@ Jo = F=HJE?Kl=H FHo?AII. 9EJDEn = FHo?AII, JDHA=@I I?DA@KlA ?ooFAH=JELAlO. -=?D FHo?AII m=n=CAI JDA JDHA=@I =IIECnA@ Jo EJ, =n@ JDA FHo?AII I?DA@KlAHI HKn =lmoIJ En@AFAn@AnJlO. 6DA onA AN?AFJEon EI JD=J = JDHA=@ En onA FHo?AII mECDJ Co Jo IlAAF BoH AN=mFlA, M=EJEnC on = ?D=nnAl oFAH=JEon =n@ >A MokAn KF >O = JDHA=@ En = @EBBAHAnJ FHo?AII. 6DA JMo FHo?AIIAI nAA@ = M=O Jo ?ooH@E­ n=JA, Io JD=J EB JDA BEHIJ D=I no HKnn=>lA JDHA=@I, EJ ?=n Co Jo IlAAF En JDA kAHnAl, =n@ JDAnJDA IA?on@FHo?AII?=nM=kA EJ KF. 6DA IJ=n@=H@ 2l=n ' JDHA=@ lE>H=HO KIAI HAn@AzLoKI Jo ?ooH@En=JA >AJMAAn FHo­ ?AIIAI. 6DA FHo?AIIAI ID=HA =??AII Jo A=?D oJDAHߣI I?DA@KlEnC GKAKAI: onA FHo?AII EI m=nEFKl=JEnC =noJDAHߣI HKn GKAKA. 6DA FHo?AIIAI mKIJ =lIo ID=HA = Bl=C FHoJA?JA@ >O = IFEn lo?k Jo ?ooH@En=JA, Io JD=J AEJDAH >oJD FHo?AIIAI @A?E@A Jo ?=ll HAn@AzLoKI oH nAE­ JDAH@oAI. .oH JDA HA=l-JEmA JDHA=@ lE>H=HO, MA M=nJA@ Jo HAmoLA =I m=nO IoKH?AI oB >lo?kEnC =I FoIIE>lA, En?lK@EnC JDAIA lo?kI. 9A HAFl=?A@ JDA lo?kA@ HKn GKAKA MEJD = non- >lo?kEnC =HH=O->=IA@ EmFlAmAnJ=JEon oB = FHo@K?AH/?onIKmAH GKAKA. 6D=J EmFlAmAn­ J=JEon EI >AOon@ JDA I?oFA oB JDEI F=FAH. )BJAH m=kEnC JD=J ?D=nCA, JDA onlO lo?k HAm=EnEnC En JDA I?DA@KlAH M=I JDA onA FHoJA?JEnC JDA ߢߢMDAJDAH Jo HAn@AzLoKIߣߣ Bl=C. 6o AlEmEn=JA JD=J onA, MA HAFl=?A@ JDA HAn@AzLoKI MEJD = KIAH-IF=?A IAm=FDoHA ?oKnJ­ EnCJDA nKm>AHoB JDHA=@IonJDA GKAKA. 6o M=EJ BoH = JDHA=@ Jo HKn, JDA FHo?AIIߣI I?DA@KlAH @A?HAmAnJI JDA IAm=FDoHA. 1B JDA HKn GKAKA EI AmFJO, JDA usemacquire MEll >lo?k KnJEl EJ EI noJ. 0=LEnC @onA Io, EJ EI CK=H=nJAA@JD=J JDAHA EI= JDHA=@onJDA HKnGKAKA: // Get next thread to run static Thread* runthread(void) { Proc *p; p = thisproc(); usemacquire(&p−>nready); return qget(&p−>ready); } 5EmEl=HlO, Jo M=kA KF = JDHA=@ ALAn onA En =noJDAH FHo?AII, EJ IKBBE?AI Jo =@@ JDA JDHA=@JoEJIFHo?AIIߣIHKnGKAKA =n@JDAnEn?HAmAnJ JDA IAm=FDoHA: // Wake up thread t to run in its process. static void wakeup(Thread *t) { Proc *p; p = t−>p; qput(&p−>ready, t); usemrelease(&p−>nready); } 6DEI EmFlAmAnJ=JEon HAmoLAI JDA nAA@ BoH JDA Bl=C =n@ JDA lo?k; moHA EmFoHJ=nJlO, JDA FHo?AII ANA?KJEnC threadwakeup EI CK=H=nJAA@ nALAH Jo >lo?k, >A?=KIA EJ ANA?KJAI usemrelease,noJ usemacquire. 5. Replacing spin locks 6DA 2l=n'KIAH-lALAl Lock EmFlAmAnJ=JEonEI =n =@=FJA@ LAHIEon oB JDA onA KIA@ En JDA kAHnAl. ) lo?k EI HAFHAIAnJA@ >O =n EnJACAH L=lKA: EI Knlo?kA@, non-zAHo EI lo?kA@. ) FHo?AIIJHEAIJoCH=>JDA lo?k >O KIEnC = JAIJ-=n@-IAJ EnIJHK?JEon Jo ?DA?k MDAJDAH JDA L=lKA EI =n@, EB Io, IAJ EJ Jo = non-zAHo L=lKA.
Recommended publications
  • Java Implementation of the Graphical User Interface of the Octopus Distributed Operating System
    Java implementation of the graphical user interface of the Octopus distributed operating system Submitted by Aram Sadogidis Advisor Prof. Spyros Lalis University of Thessaly Volos, Greece October 2012 Acknowledgements I am sincerely grateful for all the people that supported me during my Uni- versity studies. Special thanks to professor Spyros Lalis, my mentor, who had decisive influence in shaping my character as an engineer. Also many thanks to my family and friends, whose support all these years, encouraged me to keep moving forward. 1 Contents 1 Introduction 4 2 System software technologies 6 2.1 Inferno OS . 6 2.2 JavaSE and Android framework . 8 2.3 Synthetic file systems . 10 2.3.1 Styx . 10 2.3.2 Op . 12 3 Octopus OS 14 3.1 UpperWare architecture . 14 3.2 Omero, a filesystem based window system . 16 3.3 Olive, the Omero viewer . 19 3.4 Ox, the Octopus shell . 21 4 Java Octopus Terminal 23 4.1 JOlive . 24 4.2 Desktop version . 25 4.2.1 Omero package . 26 4.2.2 ui package . 27 4.3 Android version . 28 4.3.1 com.jolive.Omero . 28 4.3.2 com.jolive.ui . 29 4.3.3 Pull application's UI . 30 5 Future perspective 33 5.1 GPS resources . 33 5.2 JOp . 34 5.3 Authentication device . 34 5.4 Remote Voice commander . 34 5.5 Conclusion . 35 6 Thesis preview in Greek 38 2 List of Figures 2.1 An application operates on a synthetic file as if it is a disk file, effectively communicating with a synthetic file system server.
    [Show full text]
  • Persistent 9P Sessions for Plan 9
    Persistent 9P Sessions for Plan 9 Gorka Guardiola, [email protected] Russ Cox, [email protected] Eric Van Hensbergen, [email protected] ABSTRACT Traditionally, Plan 9 [5] runs mainly on local networks, where lost connections are rare. As a result, most programs, including the kernel, do not bother to plan for their file server connections to fail. These programs must be restarted when a connection does fail. If the kernel’s connection to the root file server fails, the machine must be rebooted. This approach suffices only because lost connections are rare. Across long distance networks, where connection failures are more common, it becomes woefully inadequate. To address this problem, we wrote a program called recover, which proxies a 9P session on behalf of a client and takes care of redialing the remote server and reestablishing con- nection state as necessary, hiding network failures from the client. This paper presents the design and implementation of recover, along with performance benchmarks on Plan 9 and on Linux. 1. Introduction Plan 9 is a distributed system developed at Bell Labs [5]. Resources in Plan 9 are presented as synthetic file systems served to clients via 9P, a simple file protocol. Unlike file protocols such as NFS, 9P is stateful: per-connection state such as which files are opened by which clients is maintained by servers. Maintaining per-connection state allows 9P to be used for resources with sophisticated access control poli- cies, such as exclusive-use lock files and chat session multiplexers. It also makes servers easier to imple- ment, since they can forget about file ids once a connection is lost.
    [Show full text]
  • Bell Labs, the Innovation Engine of Lucent
    INTERNSHIPS FOR RESEARCH ENGINEERS/COMPUTER SCIENTISTS BELL LABS DUBLIN (IRELAND) – BELL LABS STUTTGART (GERMANY) Background Candidates are expected to have some experience related to the following topics: Bell Laboratories is a leading end-to-end systems and • Operating systems, virtualisation and computer solutions research lab working in the areas of cloud architectures. and distributed computing, platforms for real-time • big-data streaming and analytics, wireless networks, Software development skills (C/C++, Python). • semantic data access, services-centric operations and Computer networks and distributed systems. thermal management. The lab is embedded in the • Optimisation techniques and algorithms. great traditions of the Bell Labs systems research, in- • Probabilistic modelling of systems performance. ternationally renowned as the birthplace of modern The following skills or interests are also desirable: information theory, UNIX, the C/C++ programming • languages, Awk, Plan 9 from Bell Labs, Inferno, the Experience with OpenStack or OpenNebula or Spin formal verification tool, and many other sys- other cloud infrastructure management software. • tems, languages, and tools. Kernel-level programming (drivers, scheduler,...). • Xen, KVM and Linux scripting/administration. We offer summer internships in our Cloud • Parallel and distributed systems programming Computing team, spread across the facilities in Dublin (Ireland) and Stuttgart (Germany), focusing (MPI, OpenMP, CUDA, MapReduce, StarSs, …). • on research enabling future cloud
    [Show full text]
  • An Introduction to Linux IPC
    An introduction to Linux IPC Michael Kerrisk © 2013 linux.conf.au 2013 http://man7.org/ Canberra, Australia [email protected] 2013-01-30 http://lwn.net/ [email protected] man7 .org 1 Goal ● Limited time! ● Get a flavor of main IPC methods man7 .org 2 Me ● Programming on UNIX & Linux since 1987 ● Linux man-pages maintainer ● http://www.kernel.org/doc/man-pages/ ● Kernel + glibc API ● Author of: Further info: http://man7.org/tlpi/ man7 .org 3 You ● Can read a bit of C ● Have a passing familiarity with common syscalls ● fork(), open(), read(), write() man7 .org 4 There’s a lot of IPC ● Pipes ● Shared memory mappings ● FIFOs ● File vs Anonymous ● Cross-memory attach ● Pseudoterminals ● proc_vm_readv() / proc_vm_writev() ● Sockets ● Signals ● Stream vs Datagram (vs Seq. packet) ● Standard, Realtime ● UNIX vs Internet domain ● Eventfd ● POSIX message queues ● Futexes ● POSIX shared memory ● Record locks ● ● POSIX semaphores File locks ● ● Named, Unnamed Mutexes ● System V message queues ● Condition variables ● System V shared memory ● Barriers ● ● System V semaphores Read-write locks man7 .org 5 It helps to classify ● Pipes ● Shared memory mappings ● FIFOs ● File vs Anonymous ● Cross-memory attach ● Pseudoterminals ● proc_vm_readv() / proc_vm_writev() ● Sockets ● Signals ● Stream vs Datagram (vs Seq. packet) ● Standard, Realtime ● UNIX vs Internet domain ● Eventfd ● POSIX message queues ● Futexes ● POSIX shared memory ● Record locks ● ● POSIX semaphores File locks ● ● Named, Unnamed Mutexes ● System V message queues ● Condition variables ● System V shared memory ● Barriers ● ● System V semaphores Read-write locks man7 .org 6 It helps to classify ● Pipes ● Shared memory mappings ● FIFOs ● File vs Anonymous ● Cross-memoryn attach ● Pseudoterminals tio a ● proc_vm_readv() / proc_vm_writev() ● Sockets ic n ● Signals ● Stream vs Datagram (vs uSeq.
    [Show full text]
  • Multithreading Design Patterns and Thread-Safe Data Structures
    Lecture 12: Multithreading Design Patterns and Thread-Safe Data Structures Principles of Computer Systems Autumn 2019 Stanford University Computer Science Department Lecturer: Chris Gregg Philip Levis PDF of this presentation 1 Review from Last Week We now have three distinct ways to coordinate between threads: mutex: mutual exclusion (lock), used to enforce critical sections and atomicity condition_variable: way for threads to coordinate and signal when a variable has changed (integrates a lock for the variable) semaphore: a generalization of a lock, where there can be n threads operating in parallel (a lock is a semaphore with n=1) 2 Mutual Exclusion (mutex) A mutex is a simple lock that is shared between threads, used to protect critical regions of code or shared data structures. mutex m; mutex.lock() mutex.unlock() A mutex is often called a lock: the terms are mostly interchangeable When a thread attempts to lock a mutex: Currently unlocked: the thread takes the lock, and continues executing Currently locked: the thread blocks until the lock is released by the current lock- holder, at which point it attempts to take the lock again (and could compete with other waiting threads). Only the current lock-holder is allowed to unlock a mutex Deadlock can occur when threads form a circular wait on mutexes (e.g. dining philosophers) Places we've seen an operating system use mutexes for us: All file system operation (what if two programs try to write at the same time? create the same file?) Process table (what if two programs call fork() at the same time?) 3 lock_guard<mutex> The lock_guard<mutex> is very simple: it obtains the lock in its constructor, and releases the lock in its destructor.
    [Show full text]
  • Semaphores Semaphores (Basic) Semaphore General Vs. Binary
    Concurrent Programming (RIO) 20.1.2012 Lesson 6 Synchronization with HW support • Disable interrupts – Good for short time wait, not good for long time wait – Not good for multiprocessors Semaphores • Interrupts are disabled only in the processor used • Test-and-set instruction (etc) Ch 6 [BenA 06] – Good for short time wait, not good for long time wait – Nor so good in single processor system • May reserve CPU, which is needed by the process holding the lock – Waiting is usually “busy wait” in a loop Semaphores • Good for mutex, not so good for general synchronization – E.g., “wait until process P34 has reached point X” Producer-Consumer Problem – No support for long time wait (in suspended state) Semaphores in C--, Java, • Barrier wait in HW in some multicore architectures – Stop execution until all cores reached barrier_waitinstruction Linux, Minix – No busy wait, because execution pipeline just stops – Not to be confused with barrier_wait thread operation 20.1.2012 Copyright Teemu Kerola 2012 1 20.1.2012 Copyright Teemu Kerola 2012 2 Semaphores (Basic) Semaphore semaphore S public create initial value integer value semafori public P(S) S.value private S.V Edsger W. Dijkstra V(S) http://en.wikipedia.org/wiki/THE_operating_system public private S.list S.L • Dijkstra, 1965, THE operating system queue of waiting processes • Protected variable, abstract data type (object) • P(S) WAIT(S), Down(S) – Allows for concurrency solutions if used properly – If value > 0, deduct 1 and proceed • Atomic operations – o/w, wait suspended in list (queue?) until released – Create (SemaName, InitValue) – P, down, wait, take, pend, • V(S) SIGNAL(S), Up(S) passeren, proberen, try, prolaad, try to decrease – If someone in queue, release one (first?) of them – V, up, signal, release, post, – o/w, increase value by one vrijgeven, verlagen, verhoog, increase 20.1.2012 Copyright Teemu Kerola 2012 3 20.1.2012 Copyright Teemu Kerola 2012 4 General vs.
    [Show full text]
  • CSC 553 Operating Systems Multiple Processes
    CSC 553 Operating Systems Lecture 4 - Concurrency: Mutual Exclusion and Synchronization Multiple Processes • Operating System design is concerned with the management of processes and threads: • Multiprogramming • Multiprocessing • Distributed Processing Concurrency Arises in Three Different Contexts: • Multiple Applications – invented to allow processing time to be shared among active applications • Structured Applications – extension of modular design and structured programming • Operating System Structure – OS themselves implemented as a set of processes or threads Key Terms Related to Concurrency Principles of Concurrency • Interleaving and overlapping • can be viewed as examples of concurrent processing • both present the same problems • Uniprocessor – the relative speed of execution of processes cannot be predicted • depends on activities of other processes • the way the OS handles interrupts • scheduling policies of the OS Difficulties of Concurrency • Sharing of global resources • Difficult for the OS to manage the allocation of resources optimally • Difficult to locate programming errors as results are not deterministic and reproducible Race Condition • Occurs when multiple processes or threads read and write data items • The final result depends on the order of execution – the “loser” of the race is the process that updates last and will determine the final value of the variable Operating System Concerns • Design and management issues raised by the existence of concurrency: • The OS must: – be able to keep track of various processes
    [Show full text]
  • Lesson-9: P and V SEMAPHORES
    Inter-Process Communication and Synchronization of Processes, Threads and Tasks: Lesson-9: P and V SEMAPHORES Chapter-9 L9: "Embedded Systems - Architecture, Programming and Design", 2015 Raj Kamal, Publs.: McGraw-Hill Education 1 1. P and V SEMAPHORES Chapter-9 L9: "Embedded Systems - Architecture, Programming and Design", 2015 Raj Kamal, Publs.: McGraw-Hill Education 2 P and V semaphores • An efficient synchronisation mechanism • POSIX 1003.1.b, an IEEE standard. • POSIX─ for portable OS interfaces in Unix. • P and V semaphore ─ represents an integer in place of binary or unsigned integers Chapter-9 L9: "Embedded Systems - Architecture, Programming and Design", 2015 Raj Kamal, Publs.: McGraw-Hill Education 3 P and V semaphore Variables • The semaphore, apart from initialization, is accessed only through two standard atomic operations─ P and V • P (for wait operation)─ derived from a Dutch word ‘Proberen’, which means 'to test'. • V (for signal passing operation)─ derived from the word 'Verhogen' which means 'to increment'. Chapter-9 L9: "Embedded Systems - Architecture, Programming and Design", 2015 Raj Kamal, Publs.: McGraw-Hill Education 4 P and V Functions for Semaphore P semaphore function signals that the task requires a resource and if not available waits for it. V semaphore function signals which the task passes to the OS that the resource is now free for the other users. Chapter-9 L9: "Embedded Systems - Architecture, Programming and Design", 2015 Raj Kamal, Publs.: McGraw-Hill Education 5 P Function─ P (&Sem1) 1. /* Decrease the semaphore variable*/ sem_1 = sem_1 1; 2. /* If sem_1 is less than 0, send a message to OS by calling a function waitCallToOS.
    [Show full text]
  • Shared Memory Programming: Threads, Semaphores, and Monitors
    Shared Memory Programming: Threads, Semaphores, and Monitors CPS343 Parallel and High Performance Computing Spring 2020 CPS343 (Parallel and HPC) Shared Memory Programming: Threads, Semaphores, and MonitorsSpring 2020 1 / 47 Outline 1 Processes The Notion and Importance of Processes Process Creation and Termination Inter-process Communication and Coordination 2 Threads Need for Light Weight Processes Differences between Threads and Processes Implementing Threads 3 Mutual Exclusion and Semaphores Critical Sections Monitors CPS343 (Parallel and HPC) Shared Memory Programming: Threads, Semaphores, and MonitorsSpring 2020 2 / 47 Outline 1 Processes The Notion and Importance of Processes Process Creation and Termination Inter-process Communication and Coordination 2 Threads Need for Light Weight Processes Differences between Threads and Processes Implementing Threads 3 Mutual Exclusion and Semaphores Critical Sections Monitors CPS343 (Parallel and HPC) Shared Memory Programming: Threads, Semaphores, and MonitorsSpring 2020 3 / 47 What is a process? A process is a program in execution. At any given time, the status of a process includes: The code that it is executing (e.g. its text). Its data: The values of its static variables. The contents of its stack { which contains its local variables and procedure call/return history. The contents of the various CPU registers { particularly the program counter, which indicates what instruction the process is to execute next. Its state { is it currently able to continue execution, or must further execution wait until some event occurs (e.g. the completion of an IO operation it has requested)? CPS343 (Parallel and HPC) Shared Memory Programming: Threads, Semaphores, and MonitorsSpring 2020 4 / 47 What is a process? The chief task of an operating system is to manage a set of processes.
    [Show full text]
  • Plan 9 from Bell Labs
    Plan 9 from Bell Labs “UNIX++ Anyone?” Anant Narayanan Malaviya National Institute of Technology FOSS.IN 2007 What is it? Advanced technology transferred via mind-control from aliens in outer space Humans are not expected to understand it (Due apologies to lisperati.com) Yeah Right • More realistically, a distributed operating system • Designed by the creators of C, UNIX, AWK, UTF-8, TROFF etc. etc. • Widely acknowledged as UNIX’s true successor • Distributed under terms of the Lucent Public License, which appears on the OSI’s list of approved licenses, also considered free software by the FSF What For? “Not only is UNIX dead, it’s starting to smell really bad.” -- Rob Pike (circa 1991) • UNIX was a fantastic idea... • ...in it’s time - 1970’s • Designed primarily as a “time-sharing” system, before the PC era A closer look at Unix TODAY It Works! But that doesn’t mean we don’t develop superior alternates GNU/Linux • GNU’s not UNIX, but it is! • Linux was inspired by Minix, which was in turn inspired by UNIX • GNU/Linux (mostly) conforms to ANSI and POSIX requirements • GNU/Linux, on the desktop, is playing “catch-up” with Windows or Mac OS X, offering little in terms of technological innovation Ok, and... • Most of the “modern ideas” we use today were “bolted” on an ancient underlying system • Don’t believe me? A “modern” UNIX Terminal Where did it go wrong? • Early UNIX, “everything is a file” • Brilliant! • Only until people started adding “features” to the system... Why you shouldn’t be working with GNU/Linux • The Socket API • POSIX • X11 • The Bindings “rat-race” • 300 system calls and counting..
    [Show full text]
  • Software Transactional Memory with Interactions 3
    Software Transactional Memory with Interactions⋆ Extended Version Marino Miculan1 and Marco Peressotti2 1 University of Udine [email protected] 2 University of Southern Denmark [email protected] Abstract Software Transactional memory (STM) is an emerging ab- straction for concurrent programming alternative to lock-based synchron- izations. Most STM models admit only isolated transactions, which are not adequate in multithreaded programming where transactions need to interact via shared data before committing. To overcome this limitation, in this paper we present Open Transactional Memory (OTM), a pro- gramming abstraction supporting safe, data-driven interactions between composable memory transactions. This is achieved by relaxing isolation between transactions, still ensuring atomicity. This model allows for loosely-coupled interactions since transaction merging is driven only by accesses to shared data, with no need to specify participants beforehand. 1 Introduction Modern multicore architectures have emphasized the importance of abstractions supporting correct and scalable multi-threaded programming. In this model, threads can collaborate by interacting on shared data structures, such as tables, message queues, buffers, etc., whose access must be regulated to avoid inconsist- encies. Traditional lock-based mechanisms (like semaphores and monitors) are notoriously difficult and error-prone, as they easily lead to deadlocks, race con- ditions and priority inversions; moreover, they are not composable and hinder parallelism, thus reducing efficiency and scalability. Transactional memory (TM) has emerged as a promising abstraction to replace locks [5, 20]. The basic idea is to mark blocks of code as atomic; then, execution of each block will appear either as if it was executed sequentially and instantaneously at some unique point in time, or, if aborted, as if it did not execute at all.
    [Show full text]
  • Semaphores Cosc 450: Programming Paradigms 06
    CoSc 450: Programming Paradigms 06 Semaphores CoSc 450: Programming Paradigms 06 Semaphore Purpose: To prevent inefficient spin lock of the await statement. Idea: Instead of spinning, the process calls a method that puts it in a special queue of PCBs, the “blocked on semaphore” queue. 71447_CH08_Chapter08.qxd 1/28/09 12:27 AM Page 422 422 Chapter 8 Process Management The PCB contains additional information to help the operating system schedule the CPU. An example is a unique process identification number assigned by the system, labeled Process ID in Figure 8.18, that serves to reference the process. Sup- pose a user wants to terminate a process before it completes execution normally, and he knows the ID number is 782. He could issue a KILL(782) command that would cause the operating system to search through the queue of PCBs, find the PCB with ID 782, remove it from the queue, and deallocate it. Another example of information stored in the PCB is a record of the total amount of CPU time used so far by the suspended process. If the CPU becomes available and the operating system must decide which of several suspended processes gets the CPU, it can use the recorded time to make a fairFigure decision. 8.19 As a job progresses through the system toward completion, it passes through several states, as Figure 8.19 shows. The figure is in the form of a state transition diagram and is another example of a finite state machine. Each transition is labeled with the event that causes the change of state.
    [Show full text]