1

I have a problem in sharing a boost named mutex across processes, which are created by different users. The first process is created by service, which logon as LocalSystem. The second process is created by myself (just execute the process normally).

Both processes run this function (C++):

void MyFunc()
{
   //Open or create the named mutex
   named_mutex mutex(open_or_create, "mymutex");
   {
      scoped_lock<named_mutex> lock(mutex);
      DoSomeWork();
   }
   named_mutex::remove("mymutex");
}

Currently, I observe that both processes are able to enter DoSomeWork() simultaneously. This problem will not happen only when the service logon as "myself", and then I run the second process as administrator.

Is there any way to resolve this issue by boost or with some simple codes, instead of this? http://support.microsoft.com/kb/193073

(I tried to set mutex name as "Global\mymutex", but no mutex can be created) (I also tried to use Windows CreateMutex(), but it also suffers from same issue, as mentioned in kb193073)

Thanks!

Simon

1 Answers1

1

If you say that as admin there is no problem, maybe it's got something to do with permissions, try this:

void MyFunc()
{
  //Open or create the named mutex
  permissions allow_all;
  allow_all.set_unrestricted();
  named_mutex mutex(open_or_create, "mymutex", allow_all);
  {
     scoped_lock<named_mutex> lock(mutex);
     DoSomeWork();
  }
  named_mutex::remove("mymutex");
}
Jorge González Lorenzo
  • 1,722
  • 1
  • 19
  • 28