cs 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/cs01550_la… · cs 1550 –project...
TRANSCRIPT
![Page 1: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/1.jpg)
CS 1550Week 7 – Project 2 Discussion
Teaching Assistant
Henrique Potter
![Page 2: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/2.jpg)
CS 1550 – Project 2 is out
• Due: Monday, October 22, 2018 @11:59pm
• Late: Wednesday, October 24, 2018 @11:59pm • 10% reduction per late day
![Page 3: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/3.jpg)
Careful when submitting your Project
• Check twice if the file you sent is not corrupt
• Check twice if you are not sending an empty zip
![Page 4: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/4.jpg)
Project 2 - Syscalls and IPC
![Page 5: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/5.jpg)
Project 2 - Syscalls and IPC
![Page 6: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/6.jpg)
Project 2 - Syscalls and IPC
![Page 7: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/7.jpg)
Project 2 - Syscalls and IPC
![Page 8: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/8.jpg)
Project 2 - Syscalls and IPC
• The first car can appear in either way.
![Page 9: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/9.jpg)
Project 2 - Syscalls and IPC
• The first car can appear in either way.
• Each car has a unique ID
![Page 10: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/10.jpg)
Project 2 - Syscalls and IPC
• The first car can appear in either way.
• Each car has a unique ID
![Page 11: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/11.jpg)
Project 2 - Syscalls and IPC
• The first car can appear in either way.
• Each car has a unique ID
• Each car takes 2 seconds to go trough.
![Page 12: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/12.jpg)
Project 2 - Syscalls and IPC
• The first car can appear in either way.
• Each car has a unique ID
• Each car takes 2 seconds to go trough.
![Page 13: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/13.jpg)
Project 2 - Syscalls and IPC
• The first car can appear in either way.
• Each car has a unique ID
• Each car takes 2 seconds to go trough.
• After the first car, another may follow it with 80% chance.
Another car follows with 80% chance
![Page 14: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/14.jpg)
Project 2 - Syscalls and IPC
• The first car can appear in either way.
• Each car has a unique ID
• Each car takes 2 seconds to go trough.
• After the first car, another may follow it with 80% chance.
• If not wait 20 seconds until another car shows up.
If not sleep for 20 seconds
![Page 15: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/15.jpg)
Project 2 - Syscalls and IPC
• When the flagperson switch to the other queue?
![Page 16: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/16.jpg)
Project 2 - Syscalls and IPC
• If there are no cars in the current queue the flag person switch.
• When the flagperson switch to the other queue?
![Page 17: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/17.jpg)
Project 2 - Syscalls and IPC
• If there are no cars in the current queue the flag person switch.
• When the flagperson switch to the other queue?
![Page 18: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/18.jpg)
Project 2 - Syscalls and IPC
• If 10 cars happens to line in the other queue. The flagperson will switch and allows cars from the other side to go trough.
• When the flagperson switch to the other queue?
![Page 19: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/19.jpg)
Project 2 - Syscalls and IPC
We want to avoid a car crash.
![Page 20: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/20.jpg)
Project 2 - Syscalls and IPC
We want to avoid a deadlock.
![Page 21: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/21.jpg)
Project 2 - Syscalls and IPC
• Each road side can be implemented as queues
Coming from Left Queue
Coming from Right Queue
![Page 22: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/22.jpg)
Project 2 - Syscalls and IPC
• Each road side can be implemented as queues
Coming from Left Queue
Coming from Right Queue
Car 1
![Page 23: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/23.jpg)
Project 2 - Syscalls and IPC
• Each road side can be implemented as queues
Coming from Left Queue
Coming from Right Queue
Car 1 Car 2
Car 3 Car 6
Car 4 Car 7
Car 5 Car 8
![Page 24: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/24.jpg)
Project 2 - Syscalls and IPC
• Each road side can be implemented as queues
Coming from Left Queue
Coming from Right Queue
Car 1 Car 2
Car 3 Car 6
Car 4 Car 7
Car 5 Car 8
• A Producer will keep adding cars to the Left(Process)
![Page 25: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/25.jpg)
Project 2 - Syscalls and IPC
• Each road side can be implemented as queues
Coming from Left Queue
Coming from Right Queue
Car 1 Car 2
Car 3 Car 6
Car 4 Car 7
Car 5 Car 8
• A Producer will keep adding cars to the Left (Process)
• Another Producer will keep adding cars to the Right (Process)
![Page 26: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/26.jpg)
Project 2 - Syscalls and IPC
• Each road side can be implemented as queues
Coming from Left Queue
Coming from Right Queue
Car 1 Car 6
Car 3 Car 7
Car 4 Car 8
Car 5
• A Producer will keep adding cars to the Left (Process)
• Another Producer will keep adding cars to the Right (Process)
The flag person (process) will consume carsfrom a queue until a switch conditionhappens. Then it consume cars from theother queue until there is no more cars.
![Page 27: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/27.jpg)
Project 2 - Syscalls and IPC
• Each road side can be implemented as queues
Coming from Left Queue
Coming from Right Queue
Car 1 Car 7
Car 3 Car 8
Car 4
Car 5
• A Producer will keep adding cars to the Left (Process)
• Another Producer will keep adding cars to the Right (Process)
The flag person (process) will consume carsfrom a queue until a switch conditionhappens. Then it consume cars from theother queue until there is no more cars.
![Page 28: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/28.jpg)
Project 2 - Syscalls and IPC
• Each road side can be implemented as queues
Coming from Left Queue
Coming from Right Queue
Car 1
Car 3
Car 4
Car 5
• A Producer will keep adding cars to the Left (Process)
• Another Producer will keep adding cars to the Right (Process)
The flag person (process) will consume carsfrom a queue until a switch conditionhappens. Then it consume cars from theother queue until there is no more cars.
![Page 29: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/29.jpg)
Project 2 - Syscalls and IPC
• Each road side can be implemented as queues
Coming from Left Queue
Coming from Right Queue
Car 3
Car 4
Car 5
• A Producer will keep adding cars to the Left (Process)
• Another Producer will keep adding cars to the Right (Process)
The flag person (process) will consume carsfrom a queue until a switch conditionhappens. Then it consume cars from theother queue until there is no more cars.
![Page 30: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/30.jpg)
Project 2 - Syscalls and IPC
struct cs1550_sem{
//Some queue of your devising};
![Page 31: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/31.jpg)
Project 2 - Syscalls and IPC
struct cs1550_sem{
//Some queue of your devising};
asmlinkage long sys_cs1550_down(struct cs1550_sem *sem)
![Page 32: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/32.jpg)
Project 2 - Syscalls and IPC
struct cs1550_sem{
//Some queue of your devising};
asmlinkage long sys_cs1550_down(struct cs1550_sem *sem)
asmlinkage long sys_cs1550_up(struct cs1550_sem *sem)
![Page 33: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/33.jpg)
Project 2 - Syscalls and IPC
Left Producerwhile (true){
}
• The producers will add cars to queues
Right Producerwhile (true){
}
Consumerwhile (true){
}
![Page 34: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/34.jpg)
Project 2 - Syscalls and IPC
Left Producerwhile (true){
}
• The producers will add cars to queues
![Page 35: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/35.jpg)
Project 2 - Syscalls and IPC
Producerwhile (true){
flip coin 0.0 to 1}
• The producers will add cars to queues
![Page 36: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/36.jpg)
Project 2 - Syscalls and IPC
Producerwhile (true){
flip coin 0.0 to 1if < 0.8
else
}
• The producers will add cars to queues
![Page 37: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/37.jpg)
Project 2 - Syscalls and IPC
Producerwhile (true){
flip coin 0.0 to 1if < 0.8
elsesleep(20)
}
• The producers will add cars to queues
![Page 38: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/38.jpg)
Project 2 - Syscalls and IPC
Producerwhile (true){
flip coin 0.0 to 1if < 0.8
down(queue1_semaphore)else
sleep(20)}
• The producers will add cars to queues
![Page 39: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/39.jpg)
Project 2 - Syscalls and IPC
Producerwhile (true){
flip coin 0.0 to 1if < 0.8
down(queue1_semaphore)set id to next caradd car to queueup(flag_semaphore)
elsesleep(20)
}
• The producers will add cars to queues
![Page 40: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/40.jpg)
Project 2 - Syscalls and IPC
Producerwhile (true){
flip coin 0.0 to 1if < 0.8
down(queue1_semaphore)set id to next caradd car to queueup(flag_semaphore)
elsesleep(20)
}
• The producers will add cars to queues
Producerwhile (true){
flip coin 0.0 to 1if < 0.8
down(queue2_semaphore)set id to next caradd car to queueup(flag_semaphore)
elsesleep(20)
}
![Page 41: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/41.jpg)
Project 2 - Syscalls and IPC
Producerwhile (true){
flip coin 0.0 to 1if < 0.8
down(queue1_semaphore)set id to next caradd car to queueup(flag_semaphore)
elsesleep(20)
}
• The producers will add cars to queues
Producerwhile (true){
flip coin 0.0 to 1if < 0.8
down(queue2_semaphore)set id to next caradd car to queueup(flag_semaphore)
elsesleep(20)
}
![Page 42: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/42.jpg)
Project 2 - Syscalls and IPC
Consumerwhile (true){}
• The producers will add cars to queues
![Page 43: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/43.jpg)
Project 2 - Syscalls and IPC
Consumerwhile (true){
down(flag_semaphore)}
• The producers will add cars to queues
![Page 44: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/44.jpg)
Project 2 - Syscalls and IPC
Consumerwhile (true){
down(flag_semaphore)check and pick a queue
}
• The producers will add cars to queues
![Page 45: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/45.jpg)
Project 2 - Syscalls and IPC
Consumerwhile (true){
down(flag_semaphore)check and pick a queueconsume a car from a queue
}
• The producers will add cars to queues
![Page 46: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/46.jpg)
Project 2 - Syscalls and IPC
Consumerwhile (true){
down(flag_semaphore)check and pick a queueconsume a car from a queueup(queue_semaphore)
}
• The producers will add cars to queues
![Page 47: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/47.jpg)
Project 2 - Syscalls and IPC
Consumerwhile (true){
down(flag_semaphore)check and pick a queueconsume a car from a queueup(queue_semaphore)
}
• The producers will add cars to queues • consumes from the same queue until switch condition happens
![Page 48: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/48.jpg)
Project 2 - Syscalls and IPC
struct cs1550_sem{
int value;//Some queue of your devising
};
asmlinkage long sys_cs1550_down(struct cs1550_sem *sem)
• Here the process can sleep.
asmlinkage long sys_cs1550_up(struct cs1550_sem *sem)
![Page 49: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/49.jpg)
Project 2 - Syscalls and IPC
struct cs1550_sem{
int value;//Some queue of your devising
};
asmlinkage long sys_cs1550_down(struct cs1550_sem *sem)
• Here the process can sleep.• Mark the task as not ready
asmlinkage long sys_cs1550_up(struct cs1550_sem *sem)
![Page 50: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/50.jpg)
Project 2 - Syscalls and IPC
struct cs1550_sem{
int value;//Some queue of your devising
};
asmlinkage long sys_cs1550_down(struct cs1550_sem *sem)
• Here the process can sleep.• Mark the task as not ready• set the current stat as “TASK_INTERRUPTIBLE”
asmlinkage long sys_cs1550_up(struct cs1550_sem *sem)
![Page 51: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/51.jpg)
Project 2 - Syscalls and IPC
struct cs1550_sem{
int value;//Some queue of your devising
};
asmlinkage long sys_cs1550_down(struct cs1550_sem *sem)
• Here the process can sleep.• Mark the task as not ready• set the current stat as “TASK_INTERRUPTIBLE”• Invoke schedule() to get next task.
asmlinkage long sys_cs1550_up(struct cs1550_sem *sem)
![Page 52: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/52.jpg)
Project 2 - Syscalls and IPC
struct cs1550_sem{
int value;//Some queue of your devising
};
asmlinkage long sys_cs1550_down(struct cs1550_sem *sem)
asmlinkage long sys_cs1550_up(struct cs1550_sem *sem)
• wake_up_process(sleeping_task);
Struct that represents a process put to sleep by the down() method
![Page 53: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/53.jpg)
Project 2 - Syscalls and IPC
• The semaphores need to be implemented as part of the kernel • We can use spin locks for that
spin_lock(&sem_lock);
spin_unlock(&sem_lock);
![Page 54: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/54.jpg)
Project 2 - Syscalls and IPC
• The implementation is composed:• Syscalls for the semaphore• The trafficsim program
![Page 55: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/55.jpg)
Project 2 - Syscalls and IPC
• Syscalls you will modify the files• Actual implementation
• linux-2.6.23.1/kernel/sys.c
• Syscall Number map• linux-2.6.23.1/arch/i386/kernel/syscall_table.S
• Exposes syscall number to C programs• linux-2.6.23.1/include/asm/unistd.h
![Page 56: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/56.jpg)
Project 2 - Syscalls and IPC
• You should print in the format:
• The flagperson is now asleep.• The flagperson is now awake.
• Car %d coming from the %c direction, blew their horn at time %d• Car %d coming from the %c direction arrived in the queue at time %d• Car %d coming from the %c direction left the construction zone at time %d.
![Page 57: CS 1550people.cs.pitt.edu/~henriquepotter/resources/rec_slides/CS01550_la… · CS 1550 –Project 2 is out •Due: Monday, October 22, 2018 @11:59pm •Late: Wednesday, October 24,](https://reader034.vdocument.in/reader034/viewer/2022042515/5f8b3cfb0da424706160cf71/html5/thumbnails/57.jpg)
CS 1550Week 7 – Project 2 Discussion
Teaching Assistant
Henrique Potter