I use semget() to get a semaphore, and initialize its VAL to 0, then I want to wait it with semop(), but it directly return. (Another process is designed to get the SEM and release it after some operations)
But if I get a SEM and init its VAL to 0 in a process, and wait it in another process, it works.
Does it mean that a process cannot block itself?
thanks!!!
like this:
int semid = semget(IPC_PRIVATE, 1, IPC_CREAT);
union semun su;
su.val = 0;
semctl(semid, 1, SETVAL, su);
struct sembuf sb;
sb.sem_num = 0;
sb.sem_op = -1;
sb.sem_flg = 0;
semop(semid, &sb, 1);