diff --git a/doc/examples.html b/doc/examples.html index 0bf9463..da4fc04 100644 --- a/doc/examples.html +++ b/doc/examples.html @@ -39,6 +39,7 @@ Tests
+See source code. +
+ +
+The program loads a text file and tokenizes its contents into words (sequences of
+alphabetic characters) using several threads in parallel to perform the task.
+Words are stored as plain std::strings or using different
+boost::flyweight configurations.
+These are the results for
+http://mattmahoney.net/dc/enwik9.zip
+(a chunk of the Wikipedia 1,000 million bytes in size) with Visual Studio 2022 on
+a Windows machine with an Intel Core i5-8265U CPU and 8 GB of RAM:
+
+ ++ std::string, 1 thread(s): 141176630 words, 11.4551 s + std::string, 8 thread(s): 141176630 words, 2.75682 s + regular flyweight, 1 thread(s): 141176630 words, 19.2284 s + regular flyweight, 8 thread(s): 141176630 words, 36.0344 s +concurrent flyweight, 1 thread(s): 141176630 words, 20.9516 s +concurrent flyweight, 8 thread(s): 141176630 words, 7.84129 s +
+boost::flyweight<std::string> performs worse
+in the parallelized scenario due to its class-wide locking upon flyweight
+creation.
+On the other hand, using
+concurrent_factory
+with no_locking and no_tracking achieves
+a higher bandwidth under parallelization.
+

Revised October 14th 2014
+Revised September 21th 2024
-© Copyright 2006-2014 Joaquín M López Muñoz. +
© Copyright 2006-2024 Joaquín M López Muñoz.
Distributed under the Boost Software
License, Version 1.0. (See accompanying file
LICENSE_1_0.txt or copy at
diff --git a/doc/reference/factories.html b/doc/reference/factories.html
index 19247b4..817be7c 100644
--- a/doc/reference/factories.html
+++ b/doc/reference/factories.html
@@ -49,6 +49,16 @@ Holders
hashed_factory"boost/flyweight/concurrent_factory_fwd.hpp" synopsis
+ "boost/flyweight/concurrent_factory.hpp" synopsis
+
+ "boost/flyweight/set_factory_fwd.hpp" synopsis
hashed_factory_class.
"boost/flyweight/concurrent_factory_fwd.hpp" synopsis+ ++namespace boost{ + +namespace flyweights{ + +template< + typename Entry,typename Key, + typename Hash=implementation defined, + typename Pred=implementation defined, + typename Allocator=implementation defined +> +class concurrent_factory_class; + +template< + typename Hash=implementation defined, + typename Pred=implementation defined, + typename Allocator=implementation defined +> +struct concurrent_factory; + +} // namespace boost::flyweights + +} // namespace boost +
+concurrent_factory_fwd.hpp forward declares the class templates
+concurrent_factory_class
+and concurrent_factory.
+
"boost/flyweight/concurrent_factory.hpp" synopsisconcurrent_factory_class
+concurrent_factory_class is a Factory
+implemented with a concurrent hash container. This factory does not require external
+locking, even in a multithreaded scenarios. It does not require any tracking mechanism
+either: values no longer referenced by any flyweight are not erased deterministically,
+but rather they are removed periodically by an internal garbage collector running
+in a dedicated thread.
+
+ ++template< + typename Entry,typename Key, + typename Hash,typename Pred,typename Allocator +> +class concurrent_factory_class +{ +public: + typedef implementation defined handle_type; + + handle_type insert(const Entry& x); + void erase(handle_type h); + const Entry& entry(handle_type h); +}; +
+Hash is a
+Default
+Constructible
+Unary Function
+taking a single argument of type Key and returning a
+value of type std::size_t in the range
+[0, std::numeric_limits<std::size_t>::max()).
+Pred is a
+Default
+Constructible
+
+Binary Predicate inducing an equivalence relation
+on elements of Key. It is required that
+a Hash object return the same value for objects
+equivalent under Pred.
+The equivalence relation on Key associated to the factory is
+that induced by Pred.
+The default arguments for Hash and Pred are
+boost::hash<Key>
+and std::equal_to<Key>, respectively.
+Allocator must be an allocator of Entry objects
+satisfying the associated C++ requirements at [lib.allocator.requirements].
+The default argument is std::allocator<Entry>. The internal
+concurrent container upon which concurrent_factory_class is based is
+constructed with default initialized objects of type Hash,
+Pred and Allocator.
+
concurrent_factory
+Factory Specifier for concurrent_factory_class.
+
+ ++template<typename Hash,typename Pred,typename Allocator> +struct concurrent_factory; +
+concurrent_factory<Hash,Pred,Allocator> is an
+MPL Metafunction
+Class such that the type
+
+ ++boost::mpl::apply< + concurrent_factory<Hash,Pred,Allocator>, + Entry,Key +>::type +
+is the same as +
+ ++ ++boost::mpl::apply< + concurrent_factory_class<boost::mpl::_1,boost::mpl::_2,Hash,Pred,Allocator>, + Entry,Key +>::type +
+This implies that Hash, Pred and Allocator
+can be
+MPL
+Placeholder Expressions resolving to the actual types used by
+concurrent_factory_class.
+
"boost/flyweight/set_factory_fwd.hpp" synopsisRevised April 24th 2019
+Revised September 20th 2024
-© Copyright 2006-2019 Joaquín M López Muñoz. +
© Copyright 2006-2024 Joaquín M López Muñoz.
Distributed under the Boost Software
License, Version 1.0. (See accompanying file
LICENSE_1_0.txt or copy at
diff --git a/doc/reference/index.html b/doc/reference/index.html
index 4d68d69..8bfd3db 100644
--- a/doc/reference/index.html
+++ b/doc/reference/index.html
@@ -72,6 +72,8 @@ Boost.Flyweight comprises the following public headers:
Revised September 1st 2014 Revised September 17th 2024 © Copyright 2006-2014 Joaquín M López Muñoz.
+ © Copyright 2006-2024 Joaquín M López Muñoz.
Distributed under the Boost Software
License, Version 1.0. (See accompanying file
LICENSE_1_0.txt or copy at
diff --git a/doc/release_notes.html b/doc/release_notes.html
index 46d518b..db14457 100644
--- a/doc/release_notes.html
+++ b/doc/release_notes.html
@@ -55,6 +55,10 @@ Acknowledgements
Revised September 14th 2024 Revised September 17th 2024 © Copyright 2006-2024 Joaquín M López Muñoz.
Distributed under the Boost Software
diff --git a/doc/tests.html b/doc/tests.html
index 01f930c..dd4f200 100644
--- a/doc/tests.html
+++ b/doc/tests.html
@@ -52,38 +52,43 @@ of Boost.Flyweight.
Revised September 1st 2014 Revised September 17th 2024 © Copyright 2006-2014 Joaquín M López Muñoz.
+ © Copyright 2006-2024 Joaquín M López Muñoz.
Distributed under the Boost Software
License, Version 1.0. (See accompanying file
LICENSE_1_0.txt or copy at
diff --git a/doc/tutorial/configuration.html b/doc/tutorial/configuration.html
index da6411d..112c765 100644
--- a/doc/tutorial/configuration.html
+++ b/doc/tutorial/configuration.html
@@ -41,6 +41,7 @@ Extending Boost.Flyweight
This specifier, which Boost.Flyweight takes by default, controls the usage of a
-factory internally based in a hash container. Values are determined to be
+factory internally based on a hash container. Values are determined to be
equivalent by means of the
+This specifier provides a factory based on a concurrent container from
+Boost.Unordered.
+The factory is particularly suitable for flyweight creation in multithreaded
+scenarios as it does not require external synchronization or tracking; so,
+it should be generally used in conjunction with
+
+Unused values (those no longer referred to by any flyweight), are periodically
+erased from the factory by a built-in garbage collector.
+
+The default types for
+is equivalent to
+
+with the same meaning as in Revised April 24th 2019 Revised September 18th 2024 © Copyright 2006-2019 Joaquín M López Muñoz.
+ © Copyright 2006-2024 Joaquín M López Muñoz.
Distributed under the Boost Software
License, Version 1.0. (See accompanying file
LICENSE_1_0.txt or copy at
diff --git a/example/Jamfile.v2 b/example/Jamfile.v2
index c30c3b5..6dc093a 100644
--- a/example/Jamfile.v2
+++ b/example/Jamfile.v2
@@ -1,6 +1,6 @@
# Boost.Flyweight examples Jamfile
#
-# Copyright 2006-2014 Joaquín M López Muñoz.
+# Copyright 2006-2024 Joaquín M López Muñoz.
# 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)
@@ -41,6 +41,11 @@ exe key_value
/boost/array//boost_array
;
+exe parallel
+ : parallel.cpp
+ : "boost/flyweight/factory_tag.hpp""boost/flyweight/hashed_factory_fwd.hpp""boost/flyweight/hashed_factory.hpp""boost/flyweight/concurrent_factory_fwd.hpp""boost/flyweight/concurrent_factory.hpp""boost/flyweight/set_factory_fwd.hpp""boost/flyweight/set_factory.hpp""boost/flyweight/assoc_container_factory_fwd.hpp"
-
+
concurrent_factory,
+ a factory based on a concurrent container from
+ Boost.Unordered
+ that provides excellent performance in multithreaded scenarios.noexcept those boost::flyweight
operations previously documented as not throwing
(issue #15).
-Exercises the default components of
flyweight.
+
+
+ test_concurrent_factory.cppExercises
+concurrent_factory
+ factory specifier.
-test_custom_factory.cppCreates a user-defined factory class and specifier.
+
-test_init.cppBoost.Flyweight static
data initialization facilities.
+
-test_intermod_holder.cpp
intermod_holder_dll.cppExercises
intermodule_holder.
+
-test_multictor.cppTests
flyweight multiple
argument and initializer-list constructors.
+
-test_no_locking.cppno_locking policy.
+
-test_no_tracking.cppno_tracking policy.
+
-test_serialization.cppExercises
flyweight serialization
capabilities.
+
test_set_factory.cpp
@@ -106,9 +111,9 @@ Future work
set_factory
factory specifier.
-
@@ -228,7 +229,7 @@ type hashed_factoryconcurrent_factoryset_factoryassoc_container_factoryboost::mpl::_1 can be used.
Binary
Predicate Pred, and indexed into the factory container
@@ -281,6 +282,65 @@ a special hash predicate special_hash and a custom allocator
>
+
+
+concurrent_factory
+Header:
+
+"boost/flyweight/concurrent_factory.hpp"
+Syntax: concurrent_factory<[Hash[,Pred[,Allocator]]]>
+no_locking and
+no_tracking:
+
+
+
+typedef flyweight<
+ std::string,
+ concurrent_factory<>,
+ no_locking,
+ no_tracking
+> concurrent_string_flyweight;
+
concurrent_factory parameters are such that the expression
+
+
+
+flyweight<T,concurrent_factory<> >
+
+
+
+flyweight<
+ T,
+ concurrent_factory<
+ boost::hash<key_value>,
+ std::equal_to<key_value>,
+ std::allocator<boost::mpl::_1>
+ >
+>
+
hashed_factory.
+set_factory
@@ -351,7 +411,7 @@ requirements:
Unique
Associative Container where equivalence of Entrys
is determined by the key_type values the entries are convertible
- to .
+ to.
-