Boost named_semaphore examples?
Asked Answered
A

1

6

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.

Agamete answered 8/3, 2011 at 10:28 Comment(0)
G
2

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

Gladi answered 19/2, 2012 at 3:11 Comment(3)
I will take a look at your link soon... Thank you.Agamete
I'm confused by this: "Both semaphore types implement wait, notify_one and notify_all as expected." I've never seen a semaphore that implements something like "notify_all". It looks like these Boost semaphores implement post, wait, try_wait, and timed_wait. Is that what you meant, or am I missing something?Tern
You described named_condition, which is not the same thing as named_semaphore.Planer

© 2022 - 2024 — McMap. All rights reserved.