Boost logo

Boost Users :

Subject: [Boost-users] build error using sharable_lock with -02 optimization
From: Magallo (m.galletti_at_[hidden])
Date: 2012-03-14 05:53:02

I'm trying to use the Boost.Interprocess library, mutexes, scoped_lock,
sharable_lock etc...

If I use a simple test program that uses mutex like this, I have no problem:

void test1()
    printf("test1 - timed_lock \n");
    printf("trying to get exlusive lock within a timeout of 5 seconds\n");

mutex(boost::interprocess::open_or_create, "MyExlusiveTimedMutex");
    boost::posix_time::ptime abs_time =
boost::posix_time::second_clock::universal_time() +
    if( mutex.timed_lock(abs_time) )
        printf("mutex acquired! do some processing...\n");
        // some processing...
        printf("unlocking mutex, quit.\n");
        printf("mutex not acquired, quit.\n");
    printf("end of test1\n");

This test is ok, it builds with no problem.

Then I try to use the scoped_lock functionalities:

void test2()
    //open or create the named mutex
    printf("creating mutex...\n");
n_mutex(boost::interprocess::open_or_create, "ipc_pri_queue_mutex");
        printf("acquiring mutex scoped_lock...\n");
        printf("mutex scoped_lock acquired...\n");

        //wait some time to simulate execution
        printf("execute program...\n");
        printf("program excuted...\n");
    printf("out of scope, sharable_lock released\n");

Also this test is ok, it builds with no problem.

Finally, I try to use the sharable_lock and I get the error:

void test3()
    //open or create the named upgradable mutex
    printf("creating mutex...\n");
        printf("acquiring mutex sharable_lock...\n");
        printf("mutex sharable_lock acquired...\n");

        //wait some time to simulate execution
        printf("execute program...\n");
        printf("program excuted...\n");
    printf("out of scope, sharable_lock released\n");

If I build this with -O2 optimization flag, I get this error:

g++ -O2 -I /usr/local/boost_1_49_0 -c main.cpp -o main.o
/usr/local/boost_1_49_0/boost/interprocess/detail/atomic.hpp: In member
function 'void
MemAlignment, FileBased,
const typename
size_t, boost::interprocess::mode_t, const void*, const
boost::interprocess::permissions&, ConstructFunc) [with ConstructFunc =
DeviceAbstraction = boost::interprocess::shared_memory_object, unsigned int
MemAlignment = 0u, bool FileBased = true, bool StoreDevice = true]':
/usr/local/boost_1_49_0/boost/interprocess/detail/atomic.hpp:316: internal
compiler error: in rewrite_stmt, at tree-into-ssa.c:1380
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:> for instructions.
*** Error code 1
make: Fatal error: Command failed for target `main.o'

If I build this without the -O2 flag, the build is ok. Why this? Please

I did this test on:
OS: Solaris 10 5/09 s10s_u7wos_08 SPARC
Compiler: sparc-sun-solaris2.10-g++ (GCC) 4.2.1 (20090222) (gccfss)

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at