Pietro
Pietro

Reputation: 13182

Boost named_semaphore examples?

I have not been able to find a good example that shows how to use boost::interprocess::named_semaphore (not even on the Boost web site).

I could see something about interprocess_semaphore, but they seem to be quite different and I do not know if what shown for one also applies to the other.

Can anybody give me some links to such examples/tutorials/documentation?

Thank you.

Upvotes: 6

Views: 6939

Answers (1)

Appleman1234
Appleman1234

Reputation: 16096

The major difference between interprocess_semaphore and named_semaphore is that the interprocess_semaphore is shared with using the shared memory ,where as named_semaphore doesn't need to be constructed (using construct) or stored in shared memory as it referenced by name instead of anonymously.

Named synchronization methods use different objects to access the same resource, but are using the same resource, where is anonymous synchronization methods need to share the same object in shared_memory or some other mechanism in order to access the same resource.

This means that named_semaphore has 3 constructors which either open or create the referenced synchronization method, in comparison to interprocess_semaphore which only has 1 constructor.

Both semaphore types implement post, wait, try_wait and timed_wait as expected.

Further information is available here and here.

One example of using a named_semaphore is available here

Upvotes: 2

Related Questions