--- /dev/null
+ <li> Changed: IndexSet::compress() and, by extension, all of the
+ "const" member functions of the IndexSet class, are now thread-safe.
+ <br>
+ (Wolfgang Bangerth, 2016/12/20)
+ </li>
+
#include <deal.II/base/config.h>
#include <deal.II/base/utilities.h>
#include <deal.II/base/exceptions.h>
+#include <deal.II/base/thread_management.h>
#include <boost/serialization/vector.hpp>
#include <vector>
#include <algorithm>
*/
mutable size_type largest_range;
+ /**
+ * A mutex that is used to synchronize operations of the do_compress() function
+ * that is called from many 'const' functions via compress().
+ */
+ mutable Threads::Mutex compress_mutex;
+
/**
* Actually perform the compress() operation.
*/
else
out << "[" << p->begin << "," << p->end-1 << "]";
- if (p !=--ranges.end())
+ if (p != --ranges.end())
out << ", ";
}
out << "}" << std::endl;
void
IndexSet::do_compress () const
{
+ // we will, in the following, modify mutable variables. this can only
+ // work in multithreaded applications if we lock the data structures
+ // via a mutex, so that users can call 'const' functions from threads
+ // in parallel (and these 'const' functions can then call compress()
+ // which itself calls the current function)
+ Threads::Mutex::ScopedLock lock (compress_mutex);
+
// see if any of the contiguous ranges can be merged. do not use
// std::vector::erase in-place as it is quadratic in the number of
// ranges. since the ranges are sorted by their first index, determining
{
return (MemoryConsumption::memory_consumption (ranges) +
MemoryConsumption::memory_consumption (is_compressed) +
- MemoryConsumption::memory_consumption (index_space_size));
+ MemoryConsumption::memory_consumption (index_space_size) +
+ sizeof (compress_mutex));
}