Created structure for program
This commit is contained in:
parent
88487d91ca
commit
6a93bb426d
37
Semaphore.c
37
Semaphore.c
@ -0,0 +1,37 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
typedef struct sem_t
|
||||||
|
{
|
||||||
|
;
|
||||||
|
} sem_t;
|
||||||
|
|
||||||
|
void* ThreadOne(void* voidPass);
|
||||||
|
void* ThreadTwo(void* voidPass);
|
||||||
|
void sem_post(sem_t* semaphore);
|
||||||
|
void sem_wait(sem_t* semaphore);
|
||||||
|
|
||||||
|
sem_t aArrived, bArrived;
|
||||||
|
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Thread A for testing multithread
|
||||||
|
void* ThreadOne(void* voidPass)
|
||||||
|
{
|
||||||
|
printf("a1\n");
|
||||||
|
sem_post(&aArrived);
|
||||||
|
sem_wait(&bArrived);
|
||||||
|
printf("a2\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Thread B for testing multithread
|
||||||
|
void* ThreadTwo(void* voidPass)
|
||||||
|
{
|
||||||
|
printf("b1\n");
|
||||||
|
sem_post(&bArrived);
|
||||||
|
sem_wait(&aArrived);
|
||||||
|
printf("b2\n");
|
||||||
|
}
|
@ -1,3 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
rm Semaphore.out
|
rm Semaphore.out
|
||||||
gcc Semaphore.c -o Semaphore.out
|
gcc Semaphore.c -o Semaphore.out
|
||||||
|
./Semaphore.out
|
||||||
|
Loading…
Reference in New Issue
Block a user