Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 540
Pietro Avatar asked Nov 06 '22 01:11

Pietro


1 Answers

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

like image 114
Appleman1234 Avatar answered Nov 11 '22 21:11

Appleman1234