mirror of
https://github.com/boostorg/interprocess.git
synced 2026-01-19 04:12:13 +00:00
#1211: Interprocess tests hang when run in parallel
#1080 boost::interprocess win32 global file mapping issue [SVN r38950]
This commit is contained in:
@@ -32,9 +32,13 @@ bool CheckEqualContainers(MyShmCont *shmcont, MyStdCont *stdcont)
|
||||
|
||||
typename MyShmCont::iterator itshm(shmcont->begin()), itshmend(shmcont->end());
|
||||
typename MyStdCont::iterator itstd(stdcont->begin());
|
||||
if((typename MyShmCont::size_type)std::distance(itshm, itshmend) != shmcont->size()){
|
||||
return false;
|
||||
}
|
||||
for(; itshm != itshmend; ++itshm, ++itstd){
|
||||
value_type val(*itstd);
|
||||
if(*itshm != val)
|
||||
const value_type &v = *itshm;
|
||||
if(v != val)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -18,17 +18,17 @@
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include "print_container.hpp"
|
||||
#include "get_compiler_name.hpp"
|
||||
#include "get_process_id_name.hpp"
|
||||
|
||||
using namespace boost::interprocess;
|
||||
|
||||
int main ()
|
||||
{
|
||||
const int memsize = 65536;
|
||||
std::string compiler_name;
|
||||
test::get_compiler_name(compiler_name);
|
||||
const char *const shMemName = compiler_name.c_str();
|
||||
std::string filename (test::get_compiler_name());
|
||||
std::string process_name;
|
||||
test::get_process_id_name(process_name);
|
||||
const char *const shMemName = process_name.c_str();
|
||||
std::string filename (test::get_process_id_name());
|
||||
filename += "_file";
|
||||
|
||||
try{
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#include <boost/interprocess/detail/move.hpp>
|
||||
#include <boost/interprocess/detail/mpl.hpp>
|
||||
#include <string>
|
||||
#include "get_compiler_name.hpp"
|
||||
#include "get_process_id_name.hpp"
|
||||
|
||||
//***************************************************************//
|
||||
// //
|
||||
@@ -96,7 +96,7 @@ bool do_test()
|
||||
typedef deque<IntType, shmem_allocator_t> MyShmDeque;
|
||||
typedef std::deque<int> MyStdDeque;
|
||||
const int Memsize = 65536;
|
||||
const char *const shMemName = test::get_compiler_name();
|
||||
const char *const shMemName = test::get_process_id_name();
|
||||
const int max = 100;
|
||||
|
||||
try{
|
||||
|
||||
@@ -30,9 +30,8 @@
|
||||
#include <stdexcept>
|
||||
#include <assert.h>
|
||||
|
||||
/*!\file
|
||||
Describes an allocator to test expand capabilities
|
||||
*/
|
||||
//!\file
|
||||
//!Describes an allocator to test expand capabilities
|
||||
|
||||
namespace boost {
|
||||
namespace interprocess {
|
||||
@@ -71,15 +70,15 @@ class dummy_test_allocator
|
||||
struct rebind
|
||||
{ typedef dummy_test_allocator<T2> other; };
|
||||
|
||||
/*!Default constructor. Never throws*/
|
||||
//!Default constructor. Never throws
|
||||
dummy_test_allocator()
|
||||
{}
|
||||
|
||||
/*!Constructor from other dummy_test_allocator. Never throws*/
|
||||
//!Constructor from other dummy_test_allocator. Never throws
|
||||
dummy_test_allocator(const dummy_test_allocator &other)
|
||||
{}
|
||||
|
||||
/*!Constructor from related dummy_test_allocator. Never throws*/
|
||||
//!Constructor from related dummy_test_allocator. Never throws
|
||||
template<class T2>
|
||||
dummy_test_allocator(const dummy_test_allocator<T2> &other)
|
||||
{}
|
||||
@@ -118,31 +117,31 @@ class dummy_test_allocator
|
||||
size_type &, const pointer & = 0)
|
||||
{ return std::pair<pointer, bool>(0, true); }
|
||||
|
||||
/*!Returns maximum the number of objects the previously allocated memory
|
||||
pointed by p can hold.*/
|
||||
//!Returns maximum the number of objects the previously allocated memory
|
||||
//!pointed by p can hold.
|
||||
size_type size(const pointer &) const
|
||||
{ return 0; }
|
||||
|
||||
/*!Allocates just one object. Memory allocated with this function
|
||||
must be deallocated only with deallocate_one().
|
||||
Throws boost::interprocess::bad_alloc if there is no enough memory*/
|
||||
//!Allocates just one object. Memory allocated with this function
|
||||
//!must be deallocated only with deallocate_one().
|
||||
//!Throws boost::interprocess::bad_alloc if there is no enough memory
|
||||
pointer allocate_one()
|
||||
{ return pointer(0); }
|
||||
|
||||
/*!Deallocates memory previously allocated with allocate_one().
|
||||
You should never use deallocate_one to deallocate memory allocated
|
||||
with other functions different from allocate_one(). Never throws*/
|
||||
//!Deallocates memory previously allocated with allocate_one().
|
||||
//!You should never use deallocate_one to deallocate memory allocated
|
||||
//!with other functions different from allocate_one(). Never throws
|
||||
void deallocate_one(const pointer &)
|
||||
{}
|
||||
};
|
||||
|
||||
/*!Equality test for same type of dummy_test_allocator*/
|
||||
//!Equality test for same type of dummy_test_allocator
|
||||
template<class T> inline
|
||||
bool operator==(const dummy_test_allocator<T> &alloc1,
|
||||
const dummy_test_allocator<T> &alloc2)
|
||||
{ return false; }
|
||||
|
||||
/*!Inequality test for same type of dummy_test_allocator*/
|
||||
//!Inequality test for same type of dummy_test_allocator
|
||||
template<class T> inline
|
||||
bool operator!=(const dummy_test_allocator<T> &alloc1,
|
||||
const dummy_test_allocator<T> &alloc2)
|
||||
|
||||
@@ -30,14 +30,11 @@
|
||||
#include <stdexcept>
|
||||
#include <assert.h>
|
||||
|
||||
/*!\file
|
||||
Describes an allocator to test expand capabilities
|
||||
*/
|
||||
//!\file
|
||||
//!Describes an allocator to test expand capabilities
|
||||
|
||||
namespace boost {
|
||||
|
||||
namespace interprocess {
|
||||
|
||||
namespace test {
|
||||
|
||||
//This allocator just allows two allocations. The first one will return
|
||||
@@ -73,17 +70,17 @@ class expand_bwd_test_allocator
|
||||
struct rebind
|
||||
{ typedef expand_bwd_test_allocator<T2> other; };
|
||||
|
||||
/*!Constructor from the segment manager. Never throws*/
|
||||
//!Constructor from the segment manager. Never throws
|
||||
expand_bwd_test_allocator(T *buffer, size_type size, difference_type offset)
|
||||
: mp_buffer(buffer), m_size(size)
|
||||
, m_offset(offset), m_allocations(0){ }
|
||||
|
||||
/*!Constructor from other expand_bwd_test_allocator. Never throws*/
|
||||
//!Constructor from other expand_bwd_test_allocator. Never throws
|
||||
expand_bwd_test_allocator(const expand_bwd_test_allocator &other)
|
||||
: mp_buffer(other.mp_buffer), m_size(other.m_size)
|
||||
, m_offset(other.m_offset), m_allocations(0){ }
|
||||
|
||||
/*!Constructor from related expand_bwd_test_allocator. Never throws*/
|
||||
//!Constructor from related expand_bwd_test_allocator. Never throws
|
||||
template<class T2>
|
||||
expand_bwd_test_allocator(const expand_bwd_test_allocator<T2> &other)
|
||||
: mp_buffer(other.mp_buffer), m_size(other.m_size)
|
||||
@@ -153,20 +150,20 @@ class expand_bwd_test_allocator
|
||||
return std::pair<pointer, bool>(0, true);
|
||||
}
|
||||
|
||||
/*!Returns maximum the number of objects the previously allocated memory
|
||||
pointed by p can hold.*/
|
||||
//!Returns maximum the number of objects the previously allocated memory
|
||||
//!pointed by p can hold.
|
||||
size_type size(const pointer &p) const
|
||||
{ (void)p; return m_size; }
|
||||
|
||||
/*!Allocates just one object. Memory allocated with this function
|
||||
must be deallocated only with deallocate_one().
|
||||
Throws boost::interprocess::bad_alloc if there is no enough memory*/
|
||||
//!Allocates just one object. Memory allocated with this function
|
||||
//!must be deallocated only with deallocate_one().
|
||||
//!Throws boost::interprocess::bad_alloc if there is no enough memory
|
||||
pointer allocate_one()
|
||||
{ return this->allocate(1); }
|
||||
|
||||
/*!Deallocates memory previously allocated with allocate_one().
|
||||
You should never use deallocate_one to deallocate memory allocated
|
||||
with other functions different from allocate_one(). Never throws*/
|
||||
//!Deallocates memory previously allocated with allocate_one().
|
||||
//!You should never use deallocate_one to deallocate memory allocated
|
||||
//!with other functions different from allocate_one(). Never throws
|
||||
void deallocate_one(const pointer &p)
|
||||
{ return this->deallocate(p, 1); }
|
||||
|
||||
@@ -176,13 +173,13 @@ class expand_bwd_test_allocator
|
||||
char m_allocations;
|
||||
};
|
||||
|
||||
/*!Equality test for same type of expand_bwd_test_allocator*/
|
||||
//!Equality test for same type of expand_bwd_test_allocator
|
||||
template<class T> inline
|
||||
bool operator==(const expand_bwd_test_allocator<T> &alloc1,
|
||||
const expand_bwd_test_allocator<T> &alloc2)
|
||||
{ return false; }
|
||||
|
||||
/*!Inequality test for same type of expand_bwd_test_allocator*/
|
||||
//!Inequality test for same type of expand_bwd_test_allocator
|
||||
template<class T> inline
|
||||
bool operator!=(const expand_bwd_test_allocator<T> &alloc1,
|
||||
const expand_bwd_test_allocator<T> &alloc2)
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include <memory>
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include "get_compiler_name.hpp"
|
||||
#include "get_process_id_name.hpp"
|
||||
|
||||
using namespace boost::interprocess;
|
||||
|
||||
@@ -26,14 +26,14 @@ int main ()
|
||||
const std::size_t FileSize = 99999*2;
|
||||
{
|
||||
//Create file with given size
|
||||
std::ofstream file(test::get_compiler_name(), std::ios::binary | std::ios::trunc);
|
||||
std::ofstream file(test::get_process_id_name(), std::ios::binary | std::ios::trunc);
|
||||
file.seekp(static_cast<std::streamoff>(FileSize-1));
|
||||
file.write("", 1);
|
||||
}
|
||||
|
||||
{
|
||||
//Create a file mapping
|
||||
file_mapping mapping(test::get_compiler_name(), read_write);
|
||||
file_mapping mapping(test::get_process_id_name(), read_write);
|
||||
//Create two mapped regions, one half of the file each
|
||||
mapped_region region (mapping
|
||||
,read_write
|
||||
@@ -66,7 +66,7 @@ int main ()
|
||||
//See if the pattern is correct in the file
|
||||
{
|
||||
//Open the file
|
||||
std::ifstream file(test::get_compiler_name(), std::ios::binary);
|
||||
std::ifstream file(test::get_process_id_name(), std::ios::binary);
|
||||
|
||||
//Create a memory buffer
|
||||
std::auto_ptr<unsigned char> memory (new unsigned char [FileSize/2 +1]);
|
||||
@@ -103,7 +103,7 @@ int main ()
|
||||
//Now check the pattern mapping a single read only mapped_region
|
||||
{
|
||||
//Create a file mapping
|
||||
file_mapping mapping(test::get_compiler_name(), read_only);
|
||||
file_mapping mapping(test::get_process_id_name(), read_only);
|
||||
|
||||
//Create a single regions, mapping all the file
|
||||
mapped_region region (mapping
|
||||
@@ -122,11 +122,11 @@ int main ()
|
||||
}
|
||||
}
|
||||
catch(std::exception &exc){
|
||||
std::remove(test::get_compiler_name());
|
||||
std::remove(test::get_process_id_name());
|
||||
std::cout << "Unhandled exception: " << exc.what() << std::endl;
|
||||
throw;
|
||||
}
|
||||
std::remove(test::get_compiler_name());
|
||||
std::remove(test::get_process_id_name());
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -120,6 +120,7 @@ int main()
|
||||
,MyStdSet
|
||||
,MyShmMultiSet
|
||||
,MyStdMultiSet>()){
|
||||
std::cout << "Error in set_test<MyShmSet>" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
if (0 != set_test<my_managed_shared_memory
|
||||
@@ -127,6 +128,7 @@ int main()
|
||||
,MyStdSet
|
||||
,MyMovableShmMultiSet
|
||||
,MyStdMultiSet>()){
|
||||
std::cout << "Error in set_test<MyMovableShmSet>" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -135,6 +137,7 @@ int main()
|
||||
,MyStdSet
|
||||
,MyMoveCopyShmMultiSet
|
||||
,MyStdMultiSet>()){
|
||||
std::cout << "Error in set_test<MyMoveCopyShmSet>" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -143,6 +146,7 @@ int main()
|
||||
,MyStdMap
|
||||
,MyShmMultiMap
|
||||
,MyStdMultiMap>()){
|
||||
std::cout << "Error in set_test<MyShmMap>" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -159,6 +163,7 @@ int main()
|
||||
,MyStdMap
|
||||
,MyMoveCopyShmMultiMap
|
||||
,MyStdMultiMap>()){
|
||||
std::cout << "Error in set_test<MyMoveCopyShmMap>" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
50
test/get_process_id_name.hpp
Normal file
50
test/get_process_id_name.hpp
Normal file
@@ -0,0 +1,50 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2004-2007. Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// See http://www.boost.org/libs/interprocess for documentation.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef BOOST_INTERPROCESS_GET_PROCESS_ID_NAME_HPP
|
||||
#define BOOST_INTERPROCESS_GET_PROCESS_ID_NAME_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
#include <boost/interprocess/detail/os_thread_functions.hpp>
|
||||
|
||||
namespace boost{
|
||||
namespace interprocess{
|
||||
namespace test{
|
||||
|
||||
inline void get_process_id_name(std::string &str)
|
||||
{
|
||||
std::stringstream sstr;
|
||||
sstr << "process_" << boost::interprocess::detail::get_current_process_id();
|
||||
str = sstr.str();
|
||||
}
|
||||
|
||||
inline const char *get_process_id_name()
|
||||
{
|
||||
static std::string str;
|
||||
get_process_id_name(str);
|
||||
return str.c_str();
|
||||
}
|
||||
|
||||
inline const char *add_to_process_id_name(const char *name)
|
||||
{
|
||||
static std::string str;
|
||||
get_process_id_name(str);
|
||||
str += name;
|
||||
return str.c_str();
|
||||
}
|
||||
|
||||
} //namespace test{
|
||||
} //namespace interprocess{
|
||||
} //namespace boost{
|
||||
|
||||
#endif //#ifndef BOOST_INTERPROCESS_GET_PROCESS_ID_NAME_HPP
|
||||
@@ -19,22 +19,6 @@
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
|
||||
#if defined(BOOST_MSVC)
|
||||
|
||||
#pragma warning(disable: 4786) // identifier truncated in debug info
|
||||
#pragma warning(disable: 4710) // function not inlined
|
||||
#pragma warning(disable: 4711) // function selected for automatic inline expansion
|
||||
#pragma warning(disable: 4514) // unreferenced inline removed
|
||||
#pragma warning(disable: 4355) // 'this' : used in base member initializer list
|
||||
#pragma warning(disable: 4511) // copy constructor could not be generated
|
||||
#pragma warning(disable: 4512) // assignment operator could not be generated
|
||||
|
||||
#if (BOOST_MSVC >= 1310)
|
||||
#pragma warning(disable: 4675) // resolved overload found with Koenig lookup
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
typedef boost::interprocess::offset_ptr<void> VP;
|
||||
|
||||
namespace N
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include <boost/interprocess/detail/move.hpp>
|
||||
#include <boost/interprocess/detail/move_iterator.hpp>
|
||||
#include <string>
|
||||
#include "get_compiler_name.hpp"
|
||||
#include "get_process_id_name.hpp"
|
||||
|
||||
namespace boost{
|
||||
namespace interprocess{
|
||||
@@ -94,7 +94,7 @@ int list_test (bool copied_allocators_equal = true)
|
||||
typedef std::list<int> MyStdList;
|
||||
typedef typename MyShmList::value_type IntType;
|
||||
const int memsize = 65536;
|
||||
const char *const shMemName = test::get_compiler_name();
|
||||
const char *const shMemName = test::get_process_id_name();
|
||||
const int max = 100;
|
||||
typedef push_data_function<DoublyLinked> push_data_t;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user