Created
July 30, 2020 17:59
-
-
Save jwparsons/b8bcfe1023296fabe6eb66dbfbaa684e to your computer and use it in GitHub Desktop.
CS 537 Spring 2020, The Extra Credit Project: Semaphores
This file contains 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
cp -r . ~cs537-1/handin/<cs-login>/ec/ | |
cd ~cs537-1/handin/<cs-login>/ec/ && make && make clean |
This file contains 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
#include "types.h" | |
#include "user.h" | |
int sem_id; | |
void | |
func(void *arg1, void *arg2) | |
{ | |
printf(1, "child\n"); | |
sem_post(sem_id); | |
exit(); | |
} | |
int main(int argc, char *argv[]){ | |
int arg1 = 0xABCDABCD; | |
int arg2 = 0xCDEFCDEF; | |
int count = 0; | |
if(sem_init(&sem_id,count) < 0){ | |
printf(1, "main: error initializing semaphore\n"); | |
exit(); | |
} | |
printf(1, "got assigned sem id %d\n", sem_id); | |
int pid1 = thread_create(&func, &arg1, &arg2); | |
if (pid1 < 0) { | |
exit(); | |
} | |
sem_wait(sem_id); | |
printf(1, "parent: end\n"); | |
thread_join(); | |
exit(); | |
} |
This file contains 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
int sem_init(int* sem_id, int count); | |
int sem_wait(int sem_id); | |
int sem_post(int sem_id); | |
int sem_destroy(int sem_id); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment