[daemon main]
#define MAX_SEMAPHORES (2)
int semid =
qsem_init(
"/some/file/for/generating/unique/key",
'q', MAX_SEMAPHORES,
true);
if(semid < 0) {
printf("ERROR: Can't initialize semaphores.\n");
return -1;
}
(... child forking codes ...)
[forked child]
(... guaranteed as atomic procedure ...)
(... some codes ...)
(... guaranteed as atomic procedure ...)
[other program which uses resource 1]
int semid =
qsem_getid(
"/some/file/for/generating/unique/key",
'q');
if(semid < 0) {
printf("ERROR: Can't get semaphore id.\n");
return -1;
}
(... guaranteed as atomic procedure ...)
bool qsem_leave(int semid, int semno)
Unlock a semaphore and leave the critical section.
int qsem_getid(const char *keyfile, int keyid)
Get the identifier of an existing semaphore set.
bool qsem_free(int semid)
Release a semaphore set from the system.
int qsem_init(const char *keyfile, int keyid, int nsems, bool recreate)
Initialize semaphores.
bool qsem_enter(int semid, int semno)
Lock a semaphore and enter a critical section.