Dear experts,
I am trying to understand a simple semaphore program written in C, and trying to insert some printf statements in the code , but there is no output at all.
#include<stdio. h>
#include<phtrea d.h>
#include<sys/ipc.h>
#include<sys/sem.h>
In the previous when I locate a printf statement in the /*printf*/ nothing is displayed, why is this? and i would be grateful if you give a small explanation of what is supposed to be happening in this program.
I am trying to understand a simple semaphore program written in C, and trying to insert some printf statements in the code , but there is no output at all.
#include<stdio. h>
#include<phtrea d.h>
#include<sys/ipc.h>
#include<sys/sem.h>
Code:
int i, nb_place;
int semid;
struct sembuf operation;
void reservation()
{
/*prinff*/
/*operation p */
operation.sem_num = 0;
operation.sem_op = -1;
operation.sem_flg = 0;
semop(semid, &operation, 1);
nb_place = nb_place -1;
/*operation v */
operation.sem_num = 0;
operation.sem_op = 1;
operation.sem_flg = 0;
semop (semid, &operation, 1);
}
main()
{
/*prinf*/
pthread_t num_thread[3];
/*creation of a semaphore initialised to value 1 */
semid = semget(12,1,IPC_CREAT|IPC_EXCL|0600);
semctl(semid,0,SETVAL,1);
for(i=0; i<3; i++)
{
/*printf*/
pthread_create(&num_thread[i], NULL, (void *(*)())reservation, NULL);
pthread_join(num_thread, NULL);
semctl(semid,0,IPC_RMID,0);
}
}
Comment