]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Provide ThreadLocalStorage::clear().
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Fri, 7 Feb 2014 01:04:47 +0000 (01:04 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Fri, 7 Feb 2014 01:04:47 +0000 (01:04 +0000)
git-svn-id: https://svn.dealii.org/trunk@32428 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/doc/news/changes.h
deal.II/include/deal.II/base/thread_local_storage.h

index c99951908f2e10ec086c988891594066a0703786..0126d3df680828cb4bc395b6da6c487ed92e34e6 100644 (file)
@@ -124,6 +124,11 @@ inconvenience this causes.
 <h3>Specific improvements</h3>
 
 <ol>
+  <li>New: ThreadLocalStorage::clear() clears out all objects allocated on the
+  current and all other threads.
+  <br>
+  (Wolfgang Bangerth, 2014/02/06)
+
   <li>Fixed: A configuration error on Debian Testing where accidentally a
   non-pic libSuiteSparse_config.a was picked up when building a shared
   library up resulting in a link error.
index dccaa2f61fc7f72c6dca4ace185b87408c464eef..70d71b75ed53564e1ab9d34eb6684e85ecfd9425 100644 (file)
@@ -1,7 +1,7 @@
 // ---------------------------------------------------------------------
 // $Id$
 //
-// Copyright (C) 2011 - 2013 by the deal.II authors
+// Copyright (C) 2011 - 2014 by the deal.II authors
 //
 // This file is part of the deal.II library.
 //
@@ -84,7 +84,7 @@ namespace Threads
     /**
      * Copy constructor. Initialize each thread local object
      * with the corresponding object of the given object.
-     **/
+     */
     ThreadLocalStorage (const ThreadLocalStorage<T> &t);
 
     /**
@@ -132,17 +132,37 @@ namespace Threads
     ThreadLocalStorage<T> &operator = (const T &t);
 
     /**
-     * Returns a reference to the internal implementation.
+     * Remove the thread-local objects stored for all threads that have
+     * created one with this object (i.e., that have called get()
+     * at least once on this thread. This includes the current thread. If you
+     * call get() subsequently on this or any other thread, new objects will
+     * again be created.
+     *
+     * If deal.II has been configured to not use multithreading, then this function
+     * does not do anything at all. Note that this of course has different semantics
+     * as in the multithreading context the objects are deleted and created again
+     * (possible by copying from a sample object, if the appropriate constructor
+     * of this class was called), whereas in the multithreaded context the object
+     * is simply not touched at all. At the same time, the purpose of this function
+     * is to release memory other threads may have allocated for their own thread
+     * local objects after which every use of this object will require some kind
+     * of initialization. This is necessary both in the multithreaded or
+     * non-multithreaded case.
+     */
+    void clear ();
+
+    /**
+     * Returns a reference to the internal Threading Building Blocks
+     * implementation. This function is really only useful if deal.II
+     * has been configured with multithreading and has no useful
+     * purpose otherwise.
      */
 #ifdef DEAL_II_WITH_THREADS
     tbb::enumerable_thread_specific<T> &
 #else
     T &
 #endif
-    get_implementation()
-    {
-      return data;
-    }
+    get_implementation();
 
   private:
 #ifdef DEAL_II_WITH_THREADS
@@ -225,6 +245,31 @@ namespace Threads
     get() = t;
     return *this;
   }
+
+
+  template <typename T>
+  inline
+#ifdef DEAL_II_WITH_THREADS
+  tbb::enumerable_thread_specific<T> &
+#else
+  T &
+#endif
+  ThreadLocalStorage<T>::get_implementation()
+  {
+    return data;
+  }
+
+
+
+  template <typename T>
+  inline
+  void
+  ThreadLocalStorage<T>::clear ()
+  {
+#ifdef DEAL_II_WITH_THREADS
+    data.clear ();
+#endif
+  }
 }   // end of implementation of namespace Threads
 
 /**

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.