Is semaphore an IPC mechanism?

前端 未结 4 851
逝去的感伤
逝去的感伤 2020-12-31 10:52

Is semaphore an IPC mechanism?

4条回答
  •  伪装坚强ぢ
    2020-12-31 11:19

    Yes, under many platforms semaphores can synchronize across processes. You would use "named" semaphores for this -- multiple processes access the object via a name, similar to filesystem objects.

    In POSIX, you can create named semaphores via sem_open(). For unamed semaphores, if the second parameter to sem_init() is nonzero, it can be interprocess, though I'm not sure exactly how an unnamed interprocess semaphore is supposed to work.

    Note that on some systems these functions may fail with ENOSYS if interprocess semaphores aren't supported (for example OpenBSD).

    In Windows, you can create named semaphores via CreateSemaphore() as @sergiom has mentioned.

提交回复
热议问题