Boost logo

Boost Users :

From: dhruva (dhruvakm_at_[hidden])
Date: 2008-05-20 23:18:43


Windows has it built it (I guess it comes from OpenVMS)

HANDLE WINAPI CreateMutex(
  LPSECURITY_ATTRIBUTES lpMutexAttributes,
  BOOL bInitialOwner,
  LPCTSTR lpName
);

OpenVMS has a small data part on the locks in which a user can store
some data. This is another form of IPC. Wish POSIX supported this
because at times I would like to know from where the lock came to me
or who owns the lock I am trying to acquire.

-dhruva

On Tue, May 20, 2008 at 7:36 PM, Ion Gaztañaga <igaztanaga_at_[hidden]> wrote:
> Jason Robertson wrote:
>> Hi,
>> I'm trying to create simple locks based on a string name. I looked at the interprocess
> >module which has a named mutex,but it seems not well suited/efficient
> for use in a single
> > process, though I know it's supposed to work.
>
> I don't recommend using Interprocess named mutex. It has different
> lifetime semantics than intra-process named mutexes and it can be less
> efficient than other mutexes.
>
> I don't know about the Named Mutex pattern, but this pattern seems a bit
> resource expensive (creating and destroying mutexes on the fly).
> Wouldn't be better just to store the mutexes in the map without seeing
> if a client has destroyed it and re-create it again?
>
> Regards,
>
> Ion
>
>> Instead, I'm just creating a map<string,weak_ptr<mutex>> in a NamedMutexManager class.
> >It's used as a singleton and uses brute force locking to implement a
> named lock pattern.
> > Main method is
>> shared_ptr<mutex> GetMutex(string name) {
>> BigLock (only one thread at a time can get a lock so we synchronize access to map)
>> check map
>> if we have entry, make sure weak_ptr hasn't been reclaimed
>> If so, make a new shared_ptr, save weak_ptr by name, return shared_ptr
>> If not, return shared_ptr copy from weak_ptr.lock()
>> If we habe no entry,
>> make a new shared_ptr, save weak_ptr by name, return shared_ptr
>> }
>> I'm just getting back to C++ after years, so I'm 99% sure there's probably a much better way.
> > Is there a better way to do an intra-process, reliable mutex by
> std::string name so I can
> > lock things by name? How are other people doing this, do you find
> > interprocess:named_mutex suitable for use in-process?
> > I had problems with it.
>> Thanks!
>> Jason
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>

-- 
Contents reflect my personal views only!

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net