Created
March 21, 2015 19:29
-
-
Save sposterkil/6ad2609d45531c5114e9 to your computer and use it in GitHub Desktop.
Counting EX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void eastbound_car() { | |
printf("Eastbound Car (PID: %d) spawned\n", getpid()); | |
// Get the Semaphore set | |
int sem_set_id = semget(SEM_KEY, NUM_SEMS, 0777); | |
// Get the Shared Memory | |
struct common *my_shared; | |
int shm_id = shmget(SHM_KEY, 0, 0); | |
my_shared = (struct common *)shmat(shm_id, 0, 0); | |
printf("Cars crossed: %d\n", my_shared->xed_count); | |
printf("Bridge Direction: %d\n", my_shared->bridge_dir); | |
... | |
} | |
output: | |
Eastbound Car (PID: 42188) spawned | |
Cars crossed: 0 | |
Bridge Direction: 0 | |
Eastbound Car (PID: 42188) is crossing the bridge | |
Eastbound Car (PID: 42188) spawned | |
Cars crossed: 1 | |
Bridge Direction: 1 | |
Eastbound Car (PID: 42188) is crossing the bridge | |
Westbound Car (PID: 42188) spawned | |
Cars crossed: 2 | |
Bridge Direction: 1 | |
Westbound Car (PID: 42188) is crossing the bridge | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment