Semaphore in nachos
Semaphore in NachOS This codec is example: class Semaphore { public: Semaphore(char* debugName, int initialValue);  ~Semap...
This part of the code demonstrates the initialization of the function and a prompter uses the semaphore to assign the vari...
Semaphore *full; Semaphore *empty; void consumer(int dummy) { while (1) { full->P(); consume the next unit of data empty->...
In the previous slide it appears since there is realized the process of the producer and the consumer and of since they ar...
void main() { empty = new Semaphore("empty", N); full = new Semaphore("full", 0); Thread *t = new Thre...
Video example http://www.youtube.com/watch?v=Kg9lQGdipZ4
Upcoming SlideShare
Loading in …5
×

Semaphore

420 views

Published on

Published in: Technology, Self Improvement
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
420
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Semaphore

  1. 1. Semaphore in nachos
  2. 2. Semaphore in NachOS This codec is example: class Semaphore { public: Semaphore(char* debugName, int initialValue); ~Semaphore(); void P(); void V(); }
  3. 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 = %dn", p, t); }
  4. 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. 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. 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); }
  7. 7. Video example http://www.youtube.com/watch?v=Kg9lQGdipZ4

×