SlideShare a Scribd company logo
Semaphore in nachos
Semaphore in NachOS This codec is example: class Semaphore { public: Semaphore(char* debugName, int initialValue);  ~Semaphore();  void P(); void V(); }
This part of the code demonstrates the initialization of the function and a prompter uses the semaphore to assign the variables in a specific place. int a = 0; Semaphore *s; void sum(int p) { int t; s->P(); a++; t = a; s->V(); printf("%d : a = %d\n", p, t); }
Semaphore *full; Semaphore *empty; void consumer(int dummy) { while (1) { full->P(); consume the next unit of data empty->V(); } } void producer(int dummy) { while (1) { empty->P(); produce the next unit of data full->V(); } }
In the previous slide it appears since there is realized the process of the producer and the consumer and of since they are called the functions P () and V () to give the step to every process and in the following slide it appears since they get about themselves to call in the principal function.
void main() { empty = new Semaphore("empty", N); full = new Semaphore("full", 0); Thread *t = new Thread("consumer"); t->Fork(consumer, 1); t = new Thread("producer"); t->Fork(producer, 1); }
Video example http://www.youtube.com/watch?v=Kg9lQGdipZ4

More Related Content

PDF
1 introducing c language
PPT
Lập trình C
PPTX
Input output functions
PDF
7 functions
PPT
Lecture 8- Data Input and Output
DOCX
Computer Architecture and Organization lab with matlab
PDF
4 operators, expressions & statements
PDF
First c program
1 introducing c language
Lập trình C
Input output functions
7 functions
Lecture 8- Data Input and Output
Computer Architecture and Organization lab with matlab
4 operators, expressions & statements
First c program

What's hot (18)

PDF
Shortcuts JAVA
PPT
Input And Output
DOCX
UNIT-II CP DOC.docx
PDF
BeepBeep 3: A declarative event stream query engine (EDOC 2015)
PDF
A "Do-It-Yourself" Specification Language with BeepBeep 3 (Talk @ Dagstuhl 2017)
PPTX
Looping Statements and Control Statements in Python
DOCX
Applications of list
PPT
Functions and pointers_unit_4
PPTX
Loops in Python
PDF
9 character string & string library
PPTX
Decision making and branching
PPTX
Ternary operator
PPTX
Expressions using operator in c
PPT
Lecture 6- Intorduction to C Programming
PPT
Unit2 C
PDF
Hacker Thursdays: An introduction to binary exploitation
Shortcuts JAVA
Input And Output
UNIT-II CP DOC.docx
BeepBeep 3: A declarative event stream query engine (EDOC 2015)
A "Do-It-Yourself" Specification Language with BeepBeep 3 (Talk @ Dagstuhl 2017)
Looping Statements and Control Statements in Python
Applications of list
Functions and pointers_unit_4
Loops in Python
9 character string & string library
Decision making and branching
Ternary operator
Expressions using operator in c
Lecture 6- Intorduction to C Programming
Unit2 C
Hacker Thursdays: An introduction to binary exploitation
Ad

Viewers also liked (8)

ODP
Nach os network
ODP
Nach os network
ODP
Encriptacion
ODP
Sockets
ODP
Sockets in nach0s
ODP
Encriptacion
ODP
Clock
PDF
User-Generated Content Campaigns: The Three Keys to Success
Nach os network
Nach os network
Encriptacion
Sockets
Sockets in nach0s
Encriptacion
Clock
User-Generated Content Campaigns: The Three Keys to Success
Ad

Similar to Semaphore (20)

PPT
Unit2 C
PPTX
C programming
PPT
Unit 5 Foc
PPTX
golang_getting_started.pptx
PPT
02 Php Vars Op Control Etc
PPTX
Programming Homework Help
PPTX
Programming ppt files (final)
PPT
Php Reusing Code And Writing Functions
PPTX
Dti2143 chapter 5
PPT
ch08.ppt
PPT
Paradigmas de Linguagens de Programacao - Aula #4
DOCX
PPS 6.6.FUNCTION INTRODUCTION & WRITING FUNCTIONS, SCOPE OF VARIABLES FUNCTIONS
DOCX
java compilerCompiler1.javajava compilerCompiler1.javaimport.docx
PDF
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdf
PPT
Hooking signals and dumping the callstack
PPT
Programming with Java: the Basics
DOC
Assignment c programming
PPTX
Php-Continuation
Unit2 C
C programming
Unit 5 Foc
golang_getting_started.pptx
02 Php Vars Op Control Etc
Programming Homework Help
Programming ppt files (final)
Php Reusing Code And Writing Functions
Dti2143 chapter 5
ch08.ppt
Paradigmas de Linguagens de Programacao - Aula #4
PPS 6.6.FUNCTION INTRODUCTION & WRITING FUNCTIONS, SCOPE OF VARIABLES FUNCTIONS
java compilerCompiler1.javajava compilerCompiler1.javaimport.docx
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdf
Hooking signals and dumping the callstack
Programming with Java: the Basics
Assignment c programming
Php-Continuation

More from naniix21_3 (10)

ODP
ODP
Semaphore
ODP
ODP
ODP
ODP
ODP
Encriptacion
ODP
Security
PPTX
Network.h
ODP
Nach os network
Semaphore
Encriptacion
Security
Network.h
Nach os network

Recently uploaded (20)

PPTX
Tartificialntelligence_presentation.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Mushroom cultivation and it's methods.pdf
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
Machine learning based COVID-19 study performance prediction
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Getting Started with Data Integration: FME Form 101
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
OMC Textile Division Presentation 2021.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Encapsulation theory and applications.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
Tartificialntelligence_presentation.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Mushroom cultivation and it's methods.pdf
SOPHOS-XG Firewall Administrator PPT.pptx
Machine learning based COVID-19 study performance prediction
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Getting Started with Data Integration: FME Form 101
A comparative analysis of optical character recognition models for extracting...
Network Security Unit 5.pdf for BCA BBA.
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
OMC Textile Division Presentation 2021.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Encapsulation_ Review paper, used for researhc scholars
Per capita expenditure prediction using model stacking based on satellite ima...
MIND Revenue Release Quarter 2 2025 Press Release
Spectral efficient network and resource selection model in 5G networks
Encapsulation theory and applications.pdf
Digital-Transformation-Roadmap-for-Companies.pptx

Semaphore

  • 2. Semaphore in NachOS This codec is example: class Semaphore { public: Semaphore(char* debugName, int initialValue); ~Semaphore(); void P(); void V(); }
  • 3. This part of the code demonstrates the initialization of the function and a prompter uses the semaphore to assign the variables in a specific place. int a = 0; Semaphore *s; void sum(int p) { int t; s->P(); a++; t = a; s->V(); printf("%d : a = %d\n", p, t); }
  • 4. Semaphore *full; Semaphore *empty; void consumer(int dummy) { while (1) { full->P(); consume the next unit of data empty->V(); } } void producer(int dummy) { while (1) { empty->P(); produce the next unit of data full->V(); } }
  • 5. In the previous slide it appears since there is realized the process of the producer and the consumer and of since they are called the functions P () and V () to give the step to every process and in the following slide it appears since they get about themselves to call in the principal function.
  • 6. void main() { empty = new Semaphore("empty", N); full = new Semaphore("full", 0); Thread *t = new Thread("consumer"); t->Fork(consumer, 1); t = new Thread("producer"); t->Fork(producer, 1); }