|
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");
boost::interprocess::named_mutex
mutex(boost::interprocess::open_or_create, "MyExlusiveTimedMutex");
boost::posix_time::ptime abs_time =
boost::posix_time::second_clock::universal_time() +
boost::posix_time::seconds(5);
if( mutex.timed_lock(abs_time) )
{
printf("mutex acquired! do some processing...\n");
//...do some processing...
printf("unlocking mutex, quit.\n");
mutex.unlock();
}
else
{
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");
boost::interprocess::named_mutex
n_mutex(boost::interprocess::open_or_create, "ipc_pri_queue_mutex");
{
printf("acquiring mutex scoped_lock...\n");
boost::interprocess::scoped_lock<boost::interprocess::named_mutex>
sc_lock(n_mutex);
printf("mutex scoped_lock acquired...\n");
//wait some time to simulate execution
printf("execute program...\n");
sleep(10);
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");
boost::interprocess::named_upgradable_mutex
n_u_mutex(boost::interprocess::open_or_create,
"ipc_pri_queue_upgradable_mutex");
{
printf("acquiring mutex sharable_lock...\n");
boost::interprocess::sharable_lock<boost::interprocess::named_upgradable_mutex>
sh_lock(n_u_mutex);
printf("mutex sharable_lock acquired...\n");
//wait some time to simulate execution
printf("execute program...\n");
sleep(10);
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
boost::interprocess::ipcdetail::managed_open_or_create_impl<DeviceAbstraction,
MemAlignment, FileBased,
StoreDevice>::priv_open_or_create(boost::interprocess::ipcdetail::create_enum_t,
const typename
boost::interprocess::managed_open_or_create_impl_device_id_t<DeviceAbstraction>::type&,
size_t, boost::interprocess::mode_t, const void*, const
boost::interprocess::permissions&, ConstructFunc) [with ConstructFunc =
boost::interprocess::ipcdetail::named_creation_functor<boost::interprocess::interprocess_upgradable_mutex,
boost::interprocess::ipcdetail::named_creation_functor_no_arg>,
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:http://forum.java.sun.com/forum.jspa?forumID=905> 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
help.
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 hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net