[Ace-users] [ace-users] ACE_Process_Mutex has different lifetime on Windows and GNU/Linux

Douglas C. Schmidt schmidt at dre.vanderbilt.edu
Wed Nov 21 07:04:26 CST 2007


Hi Lars,

   Thanks for using the PRF!

>    ACE VERSION: 5.6.1
>
>    HOST MACHINE and OPERATING SYSTEM:
>	Gentoo Linux, kernel 2.6.22 (glibc 2.6.1)
>	Windows XP service pack 3
>
>    THE $ACE_ROOT/ace/config.h FILE
>	This is the output of the ./configure script, I have done no modificatio=
>ns.
>      (apart from removing all non-code from the file to make it terser
>
>    AREA/CLASS/EXAMPLE AFFECTED:
>	ACE_Process_Semaphore lifetime semantics
>
>    DOES THE PROBLEM AFFECT:
>        EXECUTION of applications that use the ACE_Process_Semaphore
>
>    SYNOPSIS:
>	The lifetime of ACE_Process_Semaphores is different on
>	Windows and Linux.
>
>    DESCRIPTION:
>I'm using the ACE_Process_Semaphore for synchronization between some
>processes. The code is meant to work without modification on both
>windows and linux.
>My problem is that, on Linux, once one process that uses the
>semaphore exits no process launched after this can open the same
>semaphore. This is due to the fact that the POSIX function sem_unlink
>gets called in the ACE_Process_Semaphore destructor (implicitly called
>through ACE_Semaphore destructor).
>On Windows the behaviour is different, since any process that opens
>the semaphore after the first one exits still gets the same semaphore.
>
>The behaviour of the Linux semaphores is obviously due to the way that
>sem_unlink behaves.
>
>If I remove ACE_HAS_POSIX_SEM from config.h the ACE_Process_Semaphore
>will start using SysV semaphores, which work correctly.	My question is
>really if this is a conscious decision on part of the ACE team, or if it
>is an oversight.
>Shouldn't the ACE_Process_Semaphore always use SysV semaphores to ensure
>that the lifetime is correct?
>
>I also notice that if I, rather than doing ./configure, just use
>ace/config-linux.h for my config.h-file I will not get the
>ACE_HAS_POSIX_SEM macro defined, so I get the portable semantics.

This is a very interesting question.  J.T. and Steve, what are your
thoughts on how to fix this?!

thanks,

Doug

>    REPEAT BY:
>#include <ace/Process_Semaphore.h>
>#include <iostream>
>#include <ace/OS_NS_unistd.h>
>
>int main(int argc, char * argv[]) {
>    ACE_Process_Semaphore * sem;
>
>    sem =3D new ACE_Process_Semaphore(1,"my_semaphore_name");
>    if (sem->tryacquire() =3D=3D 0) {
>        ACE_OS::sleep(1);
>        sem->release();
>        delete sem;
>    }
>    else {
>        ACE_OS::sleep(2);
>        if (sem->tryacquire() =3D=3D 0) {
>            ACE_OS::sleep(1);
>            delete sem;
>        }
>        else {
>            sem =3D new ACE_Process_Semaphore(1,"my_semaphore_name");
>            if (sem->tryacquire() =3D=3D 0) {
>                std::wcout << "ACE_Process_Semaphore destructor destroys
>lock!" << std::endl;
>            }
>            else {
>                std::wcout << "ACE_Process_Semaphore destructor does not
>remove lock!" << std::endl;
>            }
>            std::cin.get();
>            delete sem;
>        }
>    }
>    return 0;
>}
>
>Run like this on windows (from command prompt): start synctest.exe &
>start synctest.exe & start synctest.exe Run like this on Linux:
>=2E/synctest & ./synctest & ./synctest
>
>Output on Windows is: ACE_Process_Semaphore destructor does not remove lo=
>ck!
>Output on Linux is: ACE_Process_Semaphore destructor destroys lock!
>
>    SAMPLE FIX/WORKAROUND:
>Dont define ACE_HAS_POSIX_SEM in config.h Not really satisfactory, since
>Linux does indeed have posix semaphores.
>
>
>
>--------------enigECCEA9C0F790FA4A26DAD4D2
>Content-Type: application/pgp-signature; name="signature.asc"
>Content-Description: OpenPGP digital signature
>Content-Disposition: attachment; filename="signature.asc"
>
>-----BEGIN PGP SIGNATURE-----
>Version: GnuPG v1.4.6 (MingW32)
>Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
>iQCVAwUBR0Gh+WvnLORTA8gHAQJI5QQApTP5tZMhUQjUHiAMaV2ntjmUUrs1CNgh
>aefXggNHwpyNDrt8x5eW7BJOAdbRN2KwGevNp4aH3iwQzrsze6FKWPmrtPkdr+YK
>M38e1hv3UVKvrnMdMtGM7N+nrZNwPlSFAfS3wxFVieKCjhJGCKCpvrxs94H6jjQU
>XMZSmdYtsP4=
>=UghK
>-----END PGP SIGNATURE-----
>
>--------------enigECCEA9C0F790FA4A26DAD4D2--
>


-- 
Dr. Douglas C. Schmidt                       Professor and Associate Chair
Electrical Engineering and Computer Science  TEL: (615) 343-8197
Vanderbilt University                        WEB: www.dre.vanderbilt.edu/~schmidt
Nashville, TN 37203                          NET: d.schmidt at vanderbilt.edu



More information about the Ace-users mailing list