Opened 15 years ago

Closed 14 years ago

#1634 closed Bugs (worksforme)

boost::interprocess::vector cannot contain volatile int

Reported by: Lars Hagström <lars@…> Owned by: Ion Gaztañaga
Milestone: To Be Determined Component: interprocess
Version: Boost Development Trunk Severity: Problem
Keywords: Cc:

Description

It does not appear to be possible to create a boost::interprocess::vector<volatile int>. When modifying the example at http://igaztanaga.drivehq.com/interprocess/interprocess/quick_guide/qg_interprocess_container.html to use volatile int instead of int I get the following long list of errors.

boost/interprocess/containers/vector.hpp: In member function ‘void boost::interprocess::vector<T, A>::push_back(const T&) [with T = volatile int, A = boost::interprocess::allocator<volatile int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void> >, boost::interprocess::iset_index> >]’:
volint.cpp:37:   instantiated from here
boost/interprocess/containers/vector.hpp:853: error: invalid conversion from ‘volatile void*’ to ‘void*’
boost/interprocess/containers/vector.hpp:853: error:   initializing argument 2 of ‘void* operator new(size_t, void*)’
boost/interprocess/allocators/allocator.hpp: In member function ‘void boost::interprocess::allocator<T, SegmentManager>::deallocate(const typename boost::interprocess::detail::pointer_to_other<typename boost::interprocess::detail::pointer_to_other<typename SegmentManager::void_pointer, const void>::type, T>::type&, size_t) [with T = volatile int, SegmentManager = boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void> >, boost::interprocess::iset_index>]’:
boost/interprocess/containers/vector.hpp:1284:   instantiated from ‘void boost::interprocess::vector<T, A>::priv_range_insert_new_allocation(T*, typename A::size_type, T*, FwdIt, FwdIt) [with FwdIt = boost::interprocess::constant_iterator<volatile int, int>, T = volatile int, A = boost::interprocess::allocator<volatile int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void> >, boost::interprocess::iset_index> >]’
boost/interprocess/containers/vector.hpp:1202:   instantiated from ‘void boost::interprocess::vector<T, A>::priv_range_insert(typename A::pointer, FwdIt, FwdIt, std::forward_iterator_tag) [with FwdIt = boost::interprocess::constant_iterator<volatile int, int>, T = volatile int, A = boost::interprocess::allocator<volatile int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void> >, boost::interprocess::iset_index> >]’
boost/interprocess/containers/vector.hpp:1772:   instantiated from ‘void boost::interprocess::vector<T, A>::priv_insert_dispatch(boost::interprocess::detail::vector_iterator<typename A::pointer>, InIt, InIt, boost::interprocess::detail::false_) [with InIt = boost::interprocess::constant_iterator<volatile int, int>, T = volatile int, A = boost::interprocess::allocator<volatile int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void> >, boost::interprocess::iset_index> >]’
boost/interprocess/containers/vector.hpp:994:   instantiated from ‘void boost::interprocess::vector<T, A>::insert(boost::interprocess::detail::vector_iterator<typename A::pointer>, InIt, InIt) [with InIt = boost::interprocess::constant_iterator<volatile int, int>, T = volatile int, A = boost::interprocess::allocator<volatile int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void> >, boost::interprocess::iset_index> >]’
boost/interprocess/containers/vector.hpp:1005:   instantiated from ‘void boost::interprocess::vector<T, A>::insert(boost::interprocess::detail::vector_iterator<typename A::pointer>, typename A::size_type, const T&) [with T = volatile int, A = boost::interprocess::allocator<volatile int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void> >, boost::interprocess::iset_index> >]’
boost/interprocess/containers/vector.hpp:946:   instantiated from ‘boost::interprocess::detail::vector_iterator<typename A::pointer> boost::interprocess::vector<T, A>::insert(boost::interprocess::detail::vector_iterator<typename A::pointer>, const T&) [with T = volatile int, A = boost::interprocess::allocator<volatile int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void> >, boost::interprocess::iset_index> >]’
boost/interprocess/containers/vector.hpp:857:   instantiated from ‘void boost::interprocess::vector<T, A>::push_back(const T&) [with T = volatile int, A = boost::interprocess::allocator<volatile int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void> >, boost::interprocess::iset_index> >]’
volint.cpp:37:   instantiated from here
boost/interprocess/allocators/allocator.hpp:157: error: invalid conversion from ‘volatile void*’ to ‘void*’
boost/interprocess/allocators/allocator.hpp:157: error:   initializing argument 1 of ‘void boost::interprocess::segment_manager_base<MemoryManager>::deallocate(void*) [with MemoryAlgorithm = boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void> >]’
/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g++-v4/bits/stl_construct.h: In function ‘void std::_Construct(_T1*, const _T2&) [with _T1 = volatile int, _T2 = volatile int]’:
/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g++-v4/bits/stl_uninitialized.h:86:   instantiated from ‘_ForwardIterator std::__uninitialized_copy_aux(_InputIterator, _InputIterator, _ForwardIterator, __false_type) [with _InputIterator = boost::interprocess::detail::move_iterator<volatile int*>, _ForwardIterator = volatile int*]’
/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g++-v4/bits/stl_uninitialized.h:113:   instantiated from ‘_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = boost::interprocess::detail::move_iterator<volatile int*>, _ForwardIterator = volatile int*]’
boost/interprocess/containers/vector.hpp:1223:   instantiated from ‘void boost::interprocess::vector<T, A>::priv_range_insert_expand_forward(T*, FwdIt, FwdIt, typename A::size_type) [with FwdIt = boost::interprocess::constant_iterator<volatile int, int>, T = volatile int, A = boost::interprocess::allocator<volatile int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void> >, boost::interprocess::iset_index> >]’
boost/interprocess/containers/vector.hpp:1187:   instantiated from ‘void boost::interprocess::vector<T, A>::priv_range_insert(typename A::pointer, FwdIt, FwdIt, std::forward_iterator_tag) [with FwdIt = boost::interprocess::constant_iterator<volatile int, int>, T = volatile int, A = boost::interprocess::allocator<volatile int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void> >, boost::interprocess::iset_index> >]’
boost/interprocess/containers/vector.hpp:1772:   instantiated from ‘void boost::interprocess::vector<T, A>::priv_insert_dispatch(boost::interprocess::detail::vector_iterator<typename A::pointer>, InIt, InIt, boost::interprocess::detail::false_) [with InIt = boost::interprocess::constant_iterator<volatile int, int>, T = volatile int, A = boost::interprocess::allocator<volatile int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void> >, boost::interprocess::iset_index> >]’
boost/interprocess/containers/vector.hpp:994:   instantiated from ‘void boost::interprocess::vector<T, A>::insert(boost::interprocess::detail::vector_iterator<typename A::pointer>, InIt, InIt) [with InIt = boost::interprocess::constant_iterator<volatile int, int>, T = volatile int, A = boost::interprocess::allocator<volatile int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void> >, boost::interprocess::iset_index> >]’
boost/interprocess/containers/vector.hpp:1005:   instantiated from ‘void boost::interprocess::vector<T, A>::insert(boost::interprocess::detail::vector_iterator<typename A::pointer>, typename A::size_type, const T&) [with T = volatile int, A = boost::interprocess::allocator<volatile int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void> >, boost::interprocess::iset_index> >]’
boost/interprocess/containers/vector.hpp:946:   instantiated from ‘boost::interprocess::detail::vector_iterator<typename A::pointer> boost::interprocess::vector<T, A>::insert(boost::interprocess::detail::vector_iterator<typename A::pointer>, const T&) [with T = volatile int, A = boost::interprocess::allocator<volatile int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void> >, boost::interprocess::iset_index> >]’
boost/interprocess/containers/vector.hpp:857:   instantiated from ‘void boost::interprocess::vector<T, A>::push_back(const T&) [with T = volatile int, A = boost::interprocess::allocator<volatile int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void> >, boost::interprocess::iset_index> >]’
volint.cpp:37:   instantiated from here
/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g++-v4/bits/stl_construct.h:81: error: invalid static_cast from type ‘volatile int*’ to type ‘void*’
boost/interprocess/mem_algo/rbtree_best_fit.hpp: In member function ‘std::pair<T*, bool> boost::interprocess::rbtree_best_fit<MutexFamily, VoidMutex>::allocation_command(boost::interprocess::allocation_type, size_t, size_t, size_t&, T*) [with T = volatile int, MutexFamily = boost::interprocess::mutex_family, VoidPointer = boost::interprocess::offset_ptr<void>]’:
boost/interprocess/segment_manager.hpp:186:   instantiated from ‘std::pair<T*, bool> boost::interprocess::segment_manager_base<MemoryManager>::allocation_command(boost::interprocess::allocation_type, size_t, size_t, size_t&, T*) [with T = volatile int, MemoryAlgorithm = boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void> >]’
boost/interprocess/allocators/allocator.hpp:178:   instantiated from ‘std::pair<typename boost::interprocess::detail::pointer_to_other<typename boost::interprocess::detail::pointer_to_other<typename SegmentManager::void_pointer, const void>::type, T>::type, bool> boost::interprocess::allocator<T, SegmentManager>::allocation_command(boost::interprocess::allocation_type, size_t, size_t, size_t&, const typename boost::interprocess::detail::pointer_to_other<typename boost::interprocess::detail::pointer_to_other<typename SegmentManager::void_pointer, const void>::type, T>::type&) [with T = volatile int, SegmentManager = boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void> >, boost::interprocess::iset_index>]’
boost/interprocess/containers/vector.hpp:305:   instantiated from ‘std::pair<typename A::pointer, bool> boost::interprocess::detail::vector_alloc_holder<A>::allocation_command(boost::interprocess::allocation_type, typename A::size_type, typename A::size_type, typename A::size_type&, const typename A::pointer&, boost::interprocess::detail::integral_constant<unsigned int, 2u>) [with A = boost::interprocess::allocator<volatile int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void> >, boost::interprocess::iset_index> >]’
boost/interprocess/containers/vector.hpp:277:   instantiated from ‘std::pair<typename A::pointer, bool> boost::interprocess::detail::vector_alloc_holder<A>::allocation_command(boost::interprocess::allocation_type, typename A::size_type, typename A::size_type, typename A::size_type&, const typename A::pointer&) [with A = boost::interprocess::allocator<volatile int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void> >, boost::interprocess::iset_index> >]’
boost/interprocess/containers/vector.hpp:1174:   instantiated from ‘void boost::interprocess::vector<T, A>::priv_range_insert(typename A::pointer, FwdIt, FwdIt, std::forward_iterator_tag) [with FwdIt = boost::interprocess::constant_iterator<volatile int, int>, T = volatile int, A = boost::interprocess::allocator<volatile int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void> >, boost::interprocess::iset_index> >]’
boost/interprocess/containers/vector.hpp:1772:   instantiated from ‘void boost::interprocess::vector<T, A>::priv_insert_dispatch(boost::interprocess::detail::vector_iterator<typename A::pointer>, InIt, InIt, boost::interprocess::detail::false_) [with InIt = boost::interprocess::constant_iterator<volatile int, int>, T = volatile int, A = boost::interprocess::allocator<volatile int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void> >, boost::interprocess::iset_index> >]’
boost/interprocess/containers/vector.hpp:994:   instantiated from ‘void boost::interprocess::vector<T, A>::insert(boost::interprocess::detail::vector_iterator<typename A::pointer>, InIt, InIt) [with InIt = boost::interprocess::constant_iterator<volatile int, int>, T = volatile int, A = boost::interprocess::allocator<volatile int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void> >, boost::interprocess::iset_index> >]’
boost/interprocess/containers/vector.hpp:1005:   instantiated from ‘void boost::interprocess::vector<T, A>::insert(boost::interprocess::detail::vector_iterator<typename A::pointer>, typename A::size_type, const T&) [with T = volatile int, A = boost::interprocess::allocator<volatile int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void> >, boost::interprocess::iset_index> >]’
boost/interprocess/containers/vector.hpp:946:   instantiated from ‘boost::interprocess::detail::vector_iterator<typename A::pointer> boost::interprocess::vector<T, A>::insert(boost::interprocess::detail::vector_iterator<typename A::pointer>, const T&) [with T = volatile int, A = boost::interprocess::allocator<volatile int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void> >, boost::interprocess::iset_index> >]’
boost/interprocess/containers/vector.hpp:857:   instantiated from ‘void boost::interprocess::vector<T, A>::push_back(const T&) [with T = volatile int, A = boost::interprocess::allocator<volatile int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void> >, boost::interprocess::iset_index> >]’
volint.cpp:37:   instantiated from here
boost/interprocess/mem_algo/rbtree_best_fit.hpp:643: error: invalid conversion from ‘volatile void*’ to ‘void*’
boost/interprocess/mem_algo/rbtree_best_fit.hpp:643: error:   initializing argument 2 of ‘static bool boost::interprocess::detail::memory_algorithm_common<MemoryAlgorithm>::try_shrink(MemoryAlgorithm*, void*, size_t, size_t, size_t&) [with MemoryAlgorithm = boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void> >]’
boost/interprocess/segment_manager.hpp:186:   instantiated from ‘std::pair<T*, bool> boost::interprocess::segment_manager_base<MemoryManager>::allocation_command(boost::interprocess::allocation_type, size_t, size_t, size_t&, T*) [with T = volatile int, MemoryAlgorithm = boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void> >]’
boost/interprocess/allocators/allocator.hpp:178:   instantiated from ‘std::pair<typename boost::interprocess::detail::pointer_to_other<typename boost::interprocess::detail::pointer_to_other<typename SegmentManager::void_pointer, const void>::type, T>::type, bool> boost::interprocess::allocator<T, SegmentManager>::allocation_command(boost::interprocess::allocation_type, size_t, size_t, size_t&, const typename boost::interprocess::detail::pointer_to_other<typename boost::interprocess::detail::pointer_to_other<typename SegmentManager::void_pointer, const void>::type, T>::type&) [with T = volatile int, SegmentManager = boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void> >, boost::interprocess::iset_index>]’
boost/interprocess/containers/vector.hpp:305:   instantiated from ‘std::pair<typename A::pointer, bool> boost::interprocess::detail::vector_alloc_holder<A>::allocation_command(boost::interprocess::allocation_type, typename A::size_type, typename A::size_type, typename A::size_type&, const typename A::pointer&, boost::interprocess::detail::integral_constant<unsigned int, 2u>) [with A = boost::interprocess::allocator<volatile int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void> >, boost::interprocess::iset_index> >]’
boost/interprocess/containers/vector.hpp:277:   instantiated from ‘std::pair<typename A::pointer, bool> boost::interprocess::detail::vector_alloc_holder<A>::allocation_command(boost::interprocess::allocation_type, typename A::size_type, typename A::size_type, typename A::size_type&, const typename A::pointer&) [with A = boost::interprocess::allocator<volatile int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void> >, boost::interprocess::iset_index> >]’
boost/interprocess/containers/vector.hpp:1174:   instantiated from ‘void boost::interprocess::vector<T, A>::priv_range_insert(typename A::pointer, FwdIt, FwdIt, std::forward_iterator_tag) [with FwdIt = boost::interprocess::constant_iterator<volatile int, int>, T = volatile int, A = boost::interprocess::allocator<volatile int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void> >, boost::interprocess::iset_index> >]’
boost/interprocess/containers/vector.hpp:1772:   instantiated from ‘void boost::interprocess::vector<T, A>::priv_insert_dispatch(boost::interprocess::detail::vector_iterator<typename A::pointer>, InIt, InIt, boost::interprocess::detail::false_) [with InIt = boost::interprocess::constant_iterator<volatile int, int>, T = volatile int, A = boost::interprocess::allocator<volatile int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void> >, boost::interprocess::iset_index> >]’
boost/interprocess/containers/vector.hpp:994:   instantiated from ‘void boost::interprocess::vector<T, A>::insert(boost::interprocess::detail::vector_iterator<typename A::pointer>, InIt, InIt) [with InIt = boost::interprocess::constant_iterator<volatile int, int>, T = volatile int, A = boost::interprocess::allocator<volatile int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void> >, boost::interprocess::iset_index> >]’
boost/interprocess/containers/vector.hpp:1005:   instantiated from ‘void boost::interprocess::vector<T, A>::insert(boost::interprocess::detail::vector_iterator<typename A::pointer>, typename A::size_type, const T&) [with T = volatile int, A = boost::interprocess::allocator<volatile int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void> >, boost::interprocess::iset_index> >]’
boost/interprocess/containers/vector.hpp:946:   instantiated from ‘boost::interprocess::detail::vector_iterator<typename A::pointer> boost::interprocess::vector<T, A>::insert(boost::interprocess::detail::vector_iterator<typename A::pointer>, const T&) [with T = volatile int, A = boost::interprocess::allocator<volatile int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void> >, boost::interprocess::iset_index> >]’
boost/interprocess/containers/vector.hpp:857:   instantiated from ‘void boost::interprocess::vector<T, A>::push_back(const T&) [with T = volatile int, A = boost::interprocess::allocator<volatile int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void> >, boost::interprocess::iset_index> >]’
volint.cpp:37:   instantiated from here
boost/interprocess/mem_algo/rbtree_best_fit.hpp:647: error: invalid conversion from ‘volatile void*’ to ‘void*’
boost/interprocess/mem_algo/rbtree_best_fit.hpp:647: error:   initializing argument 5 of ‘std::pair<void*, bool> boost::interprocess::rbtree_best_fit<MutexFamily, VoidMutex>::priv_allocation_command(boost::interprocess::allocation_type, size_t, size_t, size_t&, void*, size_t) [with MutexFamily = boost::interprocess::mutex_family, VoidPointer = boost::interprocess::offset_ptr<void>]’
make[2]: *** [CMakeFiles/volint.dir/volint.o] Error 1
make[1]: *** [CMakeFiles/volint.dir/all] Error 2
make: *** [all] Error 2

Change History (3)

comment:1 by Ion Gaztañaga, 15 years ago

I've reproduced the bug, but I'm curious to know why do you want to have a vector of volatile elements. Volatile is used for mapped I/O so it does not match very well with an standard container.

comment:2 by anonymous, 15 years ago

Simply put, I use volatile ints (in fact boost::uint32_t) to atomically signal states between processes. There is one application that "listens" to events from a lot of other applications, and they signal their states by incrementing the volatile ints and signalling a semaphore that triggers the listener. The reason for volatility is the use of atomic ops, that need volatile ints.

comment:3 by Ion Gaztañaga, 14 years ago

Resolution: worksforme
Status: newclosed

std::vector<volatile int> does not seem to be standard. both visual 7.1 and gcc 3.5 refuse to compile the code:

std::vector<volatile int> v(5);

Note: See TracTickets for help on using tickets.