Critical section problem (repetition)

Similar documents
IPC. Semaphores were chosen for synchronisation (out of several options).

Unix System Calls. Dept. CSIE

Shared Memory Segments and POSIX Semaphores 1

An Oracle Technical White Paper July Red Hat Enterprise Linux to Oracle Solaris Porting Guide

Interprocess Communication in Java

WINDOWS PRESENTATION FOUNDATION LEKTION 3

Tanden Care Provider Interfaces Submit Claim v3

Sickness benefit [Sjukpenning]

Projektet Computer: Specifikation. Objektorienterad modellering och diskreta strukturer / design. Projektet Computer: Data. Projektet Computer: Test

Outline. Review. Inter process communication Signals Fork Pipes FIFO. Spotlights

International Council on Systems Engineering. ISO/IEC/IEEE SEminar Linköping 16 november 2015

Utbytesbatterier för UPS:er 300VA VA

Testing Database Performance with HelperCore on Multi-Core Processors

System Calls and Standard I/O

openbim FM solutions and projects in Sweden Oslo, 11 September 2014 Client BIM requirements BIM in the State

1 Posix API vs Windows API

Parental benefit [Föräldrapenning]

Introduction to UNIX System Programming

Jag valde att använda Net-EPP_client.php från centralnic för att komma igång.

Parental benefits [Föräldrapenning]

Computer Systems II. Unix system calls. fork( ) wait( ) exit( ) How To Create New Processes? Creating and Executing Processes

OS: IPC I. Cooperating Processes. CIT 595 Spring Message Passing vs. Shared Memory. Message Passing: Unix Pipes

Introduction to Java

How To Write A Program On Linux (Amd64) With A Microsoft Powerpoint 2 (Amd32) (Amd86) (Orchestra) (Unix) (Windows) (Macintosh) (Apl) (Powerpoint

Swedish model for Gender Mainstreaming in ESF projects

Car Customer Service. SFK Väst, January 2016, Måns Falk, mfalk, Security Class; Proprietary

Minix Mini Unix (Minix) basically, a UNIX - compatible operating system. Minix is small in size, with microkernel-based design. Minix has been kept

Programmation Systèmes Cours 9 UNIX Domain Sockets

Application Note. Introduction AN2471/D 3/2003. PC Master Software Communication Protocol Specification

Nyheter i SAS9.4 för programmerare

SMTP-32 Library. Simple Mail Transfer Protocol Dynamic Link Library for Microsoft Windows. Version 5.2

Computer Science & Engineering

Shared Memory Introduction

Department of Electrical Engineering and Computer Science MASSACHUSETTS INSTITUTE OF TECHNOLOGY Operating System Engineering: Fall 2005

Property taxation Småhus This brochure contains information about property tax assessment for småhus 2015, 2016 and 2017

Keil C51 Cross Compiler

Green Telnet. Making the Client/Server Model Green

## Remove any existing rules -D

Application Note 49. Using the Digi TransPort Fleet Card. October 2011

Mall för kursplaner på engelska på Naturvetenskapliga fakulteten

Linux/UNIX System Programming. POSIX Shared Memory. Michael Kerrisk, man7.org c February 2015

Mekaniska klämventiler typ OV Mechanical Pinch Valves type OV

The Linux Kernel: Process Management. CS591 (Spring 2001)

Software Application Development. D2XX Programmer's Guide

How To Understand How A Process Works In Unix (Shell) (Shell Shell) (Program) (Unix) (For A Non-Program) And (Shell).Orgode) (Powerpoint) (Permanent) (Processes

KINAR13h, KINLO13h. The marking period is, for the most part, 15 working days, otherwise it s the following date:

System Calls Related to File Manipulation

Advantech AE Technical Share Document

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C

Linux Kernel Rootkit : Virtual Terminal Key Logger

CSI 402 Lecture 13 (Unix Process Related System Calls) 13 1 / 17

Development allowance and activity grant [Aktivitetsstöd och utvecklingsersättning]

Object Classes and Permissions

ELEC 377. Operating Systems. Week 1 Class 3

The Linux Programmer s Guide

INTERNATIONELLA BANKÖVERFÖRINGAR

Jorix kernel: real-time scheduling

Generalised Socket Addresses for Unix Squeak

Configuring and Administering Hyper-V in Windows Server 2012

OPERATING SYSTEMS PROCESS SYNCHRONIZATION

Socket Programming. Kameswari Chebrolu Dept. of Electrical Engineering, IIT Kanpur

Lecture 25 Systems Programming Process Control

Networks. Inter-process Communication. Pipes. Inter-process Communication

INF5140: Specification and Verification of Parallel Systems

Priority Inversion Problem and Deadlock Situations

Process definition Concurrency Process status Process attributes PROCESES 1.3

Lab 2 review PHP intro. MVC (Model View controller)

Operating Systems and Networks

Temporary parental benefit for care of children [Tillfällig föräldrapenning vid vård av barn]

Illustration 1: Diagram of program function and data flow

Schema InvoiceXMLschema xsd

Category work in courtroom talk about domestic violence: Gender as an interactional accomplishment in child custody disputes

Interface Programmera mot interface Johan Eliasson Johan Eliasson Interface kan bryta beroendekedjor Skriv generell kod «Type» Class2 Interface

Security in EIS. The Future. This lecture. Jonny Pettersson 29/4 2010

Tanden Care Provider Interfaces Reverse Claim v1

Microsoft + SOA = Sant? Joakim Linghall Principal System Engineer SOA and Business Process joakiml@microsoft.com

Stora studentgrupper och god pedagogik. Går det att kombinera?

`çéóêáöüí=eåf=ommti=_^q=j _ìëáåéëë=^êí=qéåüåçäçöó=^_

Outline of this lecture G52CON: Concepts of Concurrency

Child allowance [Barnbidrag] and large family supplement [flerbarnstillägg] [Barnbidrag och flerbarnstillägg]

ESF Jämt. Swedish model for Gender Mainstreaming in ESF projects

Overview. CISC Developments. RISC Designs. CISC Designs. VAX: Addressing Modes. Digital VAX

Lecture 24 Systems Programming in C

Glosim: Global System Image for Cluster Computing

Beställ kläder med klubblogo

Programmation Systèmes Cours 7 IPC: FIFO

Chapter 11: Input/Output Organisation. Lesson 06: Programmed IO

CSE543 - Introduction to Computer and Network Security. Module: Operating System Security

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013

Heartbleed. or: I read the news, too. Martin R. Albrecht. Information Security Group, Royal Holloway, University of London

More Repeatable Vulnerability Assessment An introduction

Shared Address Space Computing: Programming

Sjukförsäkring. If you are signed off sick for a long period. Include your family!

Quiz I Solutions MASSACHUSETTS INSTITUTE OF TECHNOLOGY Fall Department of Electrical Engineering and Computer Science

Housing allowance for families with children [Bostadsbidrag till barnfamiljer]

Exploiting Trustzone on Android


Open Access and Stockholm University: The state of affairs at the Department of Computer and System Sciences.

Tanden Care Provider Interfaces PreAssessmentSTB v3

Operating System Manual. Realtime Communication System for netx. Kernel API Function Reference.

Transcription:

C&UNIX Critical section problem (repetition) 1 Critical section problem (repetition) repeat entry section critical section exit section remainder section until false; Två processer: P 0, P 1 ej samtidigt i kritiska sektionen

C&UNIX Critical section problem (repetition) 2 Lösning var flag: array[0..1] of boolean turn : 0..1 repeat flag[i] := true; turn := j while(flag[j] and turn = j) do no-op ; critical section flag[i] := false; remainder section until f alse; P i egen flagga ej krav atomärt uppfyller Ömsesidigt exklusift Progressivt Begränsad generaliseras till n processer

C&UNIX Semaforer (repetition) 3 Semaforer (repetition) olika processer har tillgång till samma semafor S S : heltal # 0: upptaget # 1: ledig uteslutande genom: P: wait(s) V: signal(s) atomära operationer

C&UNIX Semaforer (repetition) 4 Klassiska definitioner wait(s) : while S 0 do no-op; S := S 1; signal(s) : S := S + 1 initiellt S = 1 exekveras atomärt löser många synchroniserings problem

C&UNIX System V interprocess kommmunikationsmekanismer 5 System V interprocess kommmunikationsmekanismer message queues semaphores shared memory Olika processer gemensam nyckel heltal key_t ftok ( char *pathname, char proj ); /usr/include/sys/types.h /usr/include/bits/types.h man 5 ipc

C&UNIX Sys V IPC semaforer 6 Skapa, få tillgång till, semafor: Sys V IPC semaforer #include <sys/types.h> #include <sys/ipc.h> #include <sys/sem.h> int semget ( key t key, int nsems, int semflg ); key: nsems: semflg: returvärde: nyckel för tillgång till semafor storlek på semaforarray skapa eller ej, läs-skriv rättigheter semafor ID semid, -1 vid mislyckande

C&UNIX Sys V IPC semaforer 7 argument semget(..) key: nsems: semflg: gemensam i olika processer > 0 vid skapande, tillgång == 0 tillgång existerande semafor sätts bit för bit m.h.a. operatorn, se /usr/include/linux/ipc.h #define IPC CREAT 00001000 rättigheter som vid filaccess

C&UNIX Sys V IPC semaforer 8 kontroll av semaforer int semctl (int semid, int semnum, int cmd, union semun arg); Ändrar rättigheter, värde, e.d. semid: semnum: cmd: arg: returneras av semget(..) index i semaforarray kontroll flagga optional

C&UNIX Sys V IPC semaforer 9 union semun argumentet till semctl(.. ) ej obligatoriskt ska deklareras av användaren union semun { int val; / value for SETVAL / struct semid ds buf; / buffer for IPC STAT, IPC SET / unsigned short int array;/ array for GETALL, SETALL / struct seminfo buf; / buffer for IPC INFO / };

C&UNIX Sys V IPC semaforer 10 cmd argument till semctl(.. ) SETVAL sätter semaforens värde GETVAL returnerar semaforens värde GETPID returnerar pid senaste process SETALL använder arg.array för sätta värden GETALL använder arg.array för returnera värden IPC RMID ta bort semafor

C&UNIX Sys V IPC semaforer 11 operationer på semaforer int semop ( int semid, struct sembuf sops, unsigned nsops); semid: sembuf: nsops returneras av semget(..) array med operationer antal operationer struct sembuf /* definierad i sys/sem.h */ { unsigned short int sem_num; /* semaphore number */ short int sem_op; /* semaphore operation */ short int sem_flg; /* operation flag */ };

C&UNIX Sys V IPC semaforer 12 operationer på semaforer forts. S[nsops] array med semaforer sem op > 0 inkrementerar S[sem num] sem op == 0 vänta till S[sem num == 0 sem op < 0 dekrementerar S[sem num] blockerar om resultatet < 0 misslyckas om IPC NOWAIT satt sem flg = IPC NOWAIT väntar ej sem flg = SEM UNDO undo på exit

C&UNIX Sys V IPC semaforer 13 mer info: man 2 ipc man 5 ipc /* om Sys V IPC */ man semget /* individuella funktioner */ man ipcs /* vilka allockerade resurser har jag */ man ipcrm /* tar bort resurser */ ipcrm [ shm msg sem ] id

C&UNIX Sys V Message queues 14 skapa message queue Sys V Message queues int msgget ( key t key, int msgflg ) ; int msgctl ( int msqid, int cmd, struct msqid ds buf ); #include <sys/types.h> #include <sys/ipc.h> #include <sys/msg.h> key = ftok( /home/jag, 1); msqid = msgget(key, IPC CREAT 0666) ;

C&UNIX Sys V Message queues 15 #define MSGLENGTH 128 skicka meddelande struct msgbuf{ / exempel def. i <sys/msg.h> / }; long mtype; / message type, must be > 0 / char mtext[msglength]; / message contents / int msgsnd(int msqid, struct msgbuf msgp, size t msgsz, int msgflg); returvärden: 0, 1

C&UNIX Sys V Message queues 16 läsa meddelande ssize t msgrcv ( int msqid, struct msgbuf msgp, size t msgsz, long msgtyp, int msgflg ); ssize t: returvärde: msqid: msgp: msgsz: msgtyp: msgflg: int, byte count, error, bits/types.h 1, antal bytes kopierat från msgget pekare till struct msgbuf maximala storlek mtext (bytes) typ flaggor