[Ace-users] Re: [ace-bugs] ACE_Process_Mutex acquisition fails after fork and exit of parent

Martin Corino mcorino at remedy.nl
Mon Sep 17 15:48:10 CDT 2007


Hi,

The parent process which instantiates the statically declared 
ACE_Process_Mutex becomes the owner of the process shared object.
Exiting the parent process causes the destructor of the ACE_Process_Mutex 
instance to be called which will destroy the shared object.

The way the ACE shared objects are currently implemented requires the 'owner' 
process (i.e. the process creating the first ACE_xxx instance referencing the 
shared object) to stay 'alive' until all other processes referencing the 
process shared object have terminated.

regards,
Martin.

On Monday 17 September 2007 21:36, Douglas C. Schmidt wrote:
> [Martin, there's a question for you below.]
>
> Hi Nathan,
>
>    Thanks for using the PRF.
>
> >    ACE VERSION: 5.5.1
> >
> >    HOST MACHINE and OPERATING SYSTEM:
> >        Linux Red Hat ES/AS 3.0 & 4.0 and
> >        Solaris 9, 10
> >
> >    TARGET MACHINE and OPERATING SYSTEM, if different from HOST:
> >    COMPILER NAME AND VERSION (AND PATCHLEVEL):
> >
> >    THE $ACE_ROOT/ace/config.h FILE
> >
> >=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3
> >D=
> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
> >3D=
> >
> >
> >/* There is supposed to be another way to turn this on,
> >   but I can't find it, and this should suffice. */
> >/* Tag the ACE symbols with version info to avoid name collisions. */
> >#define ACE_HAS_VERSIONED_NAMESPACE 1
> >
> >#define ACE_HAS_STANDARD_CPP_LIBRARY 1
> >#define ACE_NTRACE 1
> >#define ACE_NLOGGING 1
> >#define ACE_DEFINES_DEFAULT_WIN32_SECURITY_ATTRIBUTES 1
> >
> >#ifdef _WIN32
> >#include "config_win32.h"
> >#endif
> >
> >#ifdef __linux__
> >#include "config_linux.h"
> >#endif
> >
> >#if defined (__SUNPRO_CC)
> >//#include "config_sunos5.7.h"
> >#include "config_sunos5.8.h"
> >//#include "config_sunos5.9.h"
> >#endif
> >
> >/* Get around bug for VS.NET 2003 */
> >#if (_MSC_VER >=3D 1300 && _MSC_VER < 1400)
> >#undef ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION_EXPORT
> >#endif
> >
> >=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3
> >D=
> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
> >3D=
> >
> >
> >    THE $ACE_ROOT/include/makeinclude/platform_macros.GNU FILE
> >        for Linux:    platform_linux.GNU
> >        for Solaris:  platform_sunos5_sunc++.GNU
> >
> >    CONTENTS OF $ACE_ROOT/bin/MakeProjectCreator/config/default.features
> >    (used by MPC when you generate your own makefiles):
> >
> >    AREA/CLASS/EXAMPLE AFFECTED:
> >
> >    DOES THE PROBLEM AFFECT:
> >        COMPILATION?
> >        LINKING?
> >        EXECUTION?
> >            Yes.
> >        OTHER (please specify)?
> >
> >    SYNOPSIS:
> >        ACE_Process_Mutex acquisition fails after fork and exit of
> >parent.
> >
> >    DESCRIPTION:
> >        If you statically declare a named ACE_Process_Mutex object on
> >        Linux or Solaris, then fork(), and then exit the parent process,
> >        the child process will be unable to acquire the mutex.
> >        It fails with EINVAL.
>
> Martin, is this something you could take a look at?
>
> Thanks,
>
>         Doug
>
> >    REPEAT BY:
> >        Here is a small test program that illustrates the problem.
> >
> >#include "ace/ACE.h"
> >#include "ace/Process_Mutex.h"
> >
> >ACE_Process_Mutex foo_mutex("test_mut");
> >
> >main()
> >{
> >    if (fork() > 0)
> >    {
> >        printf("Main process exiting\n");
> >        exit(0);
> >    }
> >
> >    printf("About to acquire...\n");
> >    sleep(5);
> >    if (foo_mutex.tryacquire())
> >        perror("Acquire failed");
> >    else
> >    {
> >        printf("Acquire succeeded\n");
> >        foo_mutex.release();
> >    }
> >}

-- 
----------------------------------------------------------------------
                           Martin J.N. Corino | Remedy IT Expertise BV
          Postbus 101 |  2650 AC Berkel en Rodenrijs | The Netherlands
                       tel: +31 (10) 522 0139 | fax: +31 (33) 246 6511
                                  World Wide Web: http://www.remedy.nl
----------------------------------------------------------------------



More information about the Ace-users mailing list