On Linux, where semaphores are implemented without any system resources, it sem_initsimply populates the elements of the structure sem_t, and therefore nothing bad will happen if it calls more than once. However, on the whole, much worse can happen.
If it sem_tis just a dummy object containing a pointer to the selected object (note: this cannot work for process semaphores), you will leak memory by calling sem_initseveral times.
Similarly, if you sem_tsimply contained a link (for example, the file descriptor number) to a kernel-managed resource, you could leak these kernel resources by calling sem_initmore than once.
, , / sem_t ( - ), , sem_init sem_t, .
POSIX , (, , , ) undefined, , .