
CSyncCollection
v1.10 A templatized collection with thread synchronization
Welcome to CSyncCollection, an C++ class which implements a templatized collection which implements
Windows thread synchronisation with timeouts for
both adding and removing. In other words when you "Add", you can specify a
timeout to wait for if the collection is full and when you "Remove" data from
the collection you can specify a timeout to wait for if the collection is empty.
Making the class templatized means that you can store any type of data you want
in it. In addition templates are used to define various collection types. The
code comes with predefined templates for both a stack and queue collection,
using MFC and STL containers.
The enclosed zip file contains
source for the class and a test program which implements a simulation of the
classic consumer / producer thread synchronisation example.
Copyright
- You are allowed to include the source code in
any product (commercial, shareware, freeware or otherwise) when your product
is released in binary form.
- You are allowed to modify the source code in
any way you want except you cannot modify the copyright details at the top
of each module.
- If you want to distribute source code with
your application, then you are only allowed to distribute versions released
by the author. This is to maintain a single distribution point for the
source code.
Updates
v1.0 (26 January 2002)
V1.01 (6 April 2002)
- Sorted out some linker
problems for the Win32 Debug and Win32 Release build configurations.
V1.02 (7 April 2002)
- Added a CEvent to the main class to allow synchronisation with data becoming available in the collection without actually having to remove it.
V1.03 (23 November 2003)
- Fixed a potential thread race condition in
CSyncCollection::Remove
V1.04 (26 November 2004)
- Fixed a number of compiler warnings when the code is
compiled on VC .Net 2003
V1.05 (30 May 2005)
- Now uses a auto-reset event to signal that items are available instead of a manual reset. Also the event is now created using the Win32 API rather than using the MFC CEvent wrapper class.
- Updated the text in some of the TRACE statements.
V1.06 (10 April 2006)
- The CSyncCollection class now provides Lock and unlock methods to allow
external synchronisation.
- CSyncCollection::GetSize, Add, Remove & Close now includes a parameter
which decides if internal locking should be done. Again this allows more
fine tuned external synchronisation of the class
- Addition of a CCSYNCCOLLECTION_EXT_CLASS macro to make it more easier to
use the class in an extension dll.
- Updated the documentation to use the same style as the web site.
- Did a spell check of the documentation.
V1.06 (10 April 2006)
- The CSyncCollection class now provides Lock and unlock methods to allow
external synchronisation.
V1.07 (2 May 2006)
- Removed the need to have the collection class methods virtual. After all
you can think of C++ templates as compile time polymorphism while virtual
functions give you runtime polymorphism.
V1.08 (7 July 2008)
- Updated copyright details.
- Removed the CSYNCCOLLECTION_EXT_CLASS proprocessor value as it is not
required since the class is template based.
- The code has now been updated to support VC 2005 or later only.
- Updated the sample app to clean compile on VC 2008
- Code now compiles cleanly using Code Analysis (/analyze)
- Code now uses newer C++ style casts instead of C style casts.
V1.09 (27 May 2011)
- Updated copyright details
- Removed usage of CSingleLock m_sl member variable as "CSingleLock"
class is not designed to be used across multiple threads. Thanks to Serhiy
Pavlov for reporting this issue.
V1.10 (10 December 2011)
- Removed the unnecessary "CSyncData" class.
- Two new container classes
have now been provided which use STL containers. They are CSyncQueueDataSTL
and CSyncStackDataSTL. To make these classes available you need to define
the processor value "CSYNCCOLLECTION_USE_STL" before you include
SyncCollection.h.
- Replaced MFC CCriticalSection usage with direct Win32
equivalent. Removed all occurences of CSingleLock from source code. Replaced
all occurrences of TRACE with ATLTRACE. All these changes allows the code to
now operate in non MFC/ATL Windows projects.