1570af302Sopenharmony_ci// commit: f70375df85d26235a45e74559afd69be59e5ff99 2020-10-28 2570af302Sopenharmony_ci#define _GNU_SOURCE 1 3570af302Sopenharmony_ci#include <fcntl.h> 4570af302Sopenharmony_ci#include <stdlib.h> 5570af302Sopenharmony_ci#include <semaphore.h> 6570af302Sopenharmony_ci 7570af302Sopenharmony_ciint main() 8570af302Sopenharmony_ci{ 9570af302Sopenharmony_ci char buf[] = "mysemXXXXXX"; 10570af302Sopenharmony_ci if (!mktemp(buf)) return 1; 11570af302Sopenharmony_ci // open twice 12570af302Sopenharmony_ci sem_t *sem = sem_open(buf, O_CREAT|O_EXCL, 0600, 0); 13570af302Sopenharmony_ci sem_open(buf, 0); 14570af302Sopenharmony_ci sem_unlink(buf); 15570af302Sopenharmony_ci // close once 16570af302Sopenharmony_ci sem_close(sem); 17570af302Sopenharmony_ci // semaphore should be still mapped 18570af302Sopenharmony_ci sem_post(sem); 19570af302Sopenharmony_ci} 20