Skip to content

Instantly share code, notes, and snippets.

@jwparsons
Created July 30, 2020 17:59
Show Gist options
  • Save jwparsons/b8bcfe1023296fabe6eb66dbfbaa684e to your computer and use it in GitHub Desktop.
Save jwparsons/b8bcfe1023296fabe6eb66dbfbaa684e to your computer and use it in GitHub Desktop.
CS 537 Spring 2020, The Extra Credit Project: Semaphores
cp -r . ~cs537-1/handin/<cs-login>/ec/
cd ~cs537-1/handin/<cs-login>/ec/ && make && make clean
#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();
}
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