Update of /cvsroot/boost/boost/boost/interprocess/detail
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv28501
Modified Files:
managed_open_or_create_impl.hpp
Log Message:
Fixed race condition if a shared memory segment is being created/initialized
for the first time. Thanks to Paul Poulin.
Index: managed_open_or_create_impl.hpp
===================================================================
RCS file:
/cvsroot/boost/boost/boost/interprocess/detail/managed_open_or_create_impl.hpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- managed_open_or_create_impl.hpp 23 Mar 2007 16:05:01 -0000 1.2
+++ managed_open_or_create_impl.hpp 14 Apr 2007 10:34:33 -0000 1.3
@@ -296,33 +296,27 @@
throw interprocess_exception(error_info(corrupted_error));
}
- mapped_region region(dev, read_write, 0, 0, addr);
+ mapped_region region(dev, read_write, 0, 0, addr);
- volatile boost::uint32_t *addr =
- static_cast<boost::uint32_t*>(region.get_address());
+ volatile boost::uint32_t *addr =
static_cast<boost::uint32_t*>(region.get_address());
- boost::uint32_t value;
+ boost::uint32_t value = detail::atomic_read32(addr);
+
+ // wait if shared segment isn't initialized
+ while(value == InitializingSegment || value == UninitializedSegment){
+ detail::thread_yield();
+ value = detail::atomic_read32(addr);
+ }
- switch(detail::atomic_read32(addr)){
- case UninitializedSegment:
- case InitializingSegment:
- do{
- detail::thread_yield();
- value = detail::atomic_read32(addr);
- }
- while(value == InitializingSegment || value ==
UninitializedSegment);
- case CorruptedSegment:
- throw interprocess_exception(error_info(corrupted_error));
- break;
- case InitializedSegment:
- construct_func((char*)region.get_address() +
ManagedOpenOrCreateUserOffset, region.get_size(), false);
- //All ok, just move resources to the external mapped region
- mregion.swap(region);
- break;
- default:
- throw interprocess_exception(error_info(corrupted_error));
- break;
- }
+ if(value != InitializedSegment){
+ throw interprocess_exception(error_info(corrupted_error));
+ }
+
+ // InitializedSegment
+ construct_func((char*)region.get_address() +
ManagedOpenOrCreateUserOffset, region.get_size(), false);
+
+ // All ok, just move resources to the external mapped region
+ mregion.swap(region);
}
}
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Boost-cvs mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/boost-cvs