I am writing a Server application which takes data from multiple sources at once and stores it in it's internal database (currently a std::set
).
I have just been looking at Microsoft's ConcRT PPL data structures and wondering about how their efficiency compares to using a fine-grained mutex on a std::unordered_set
. For example, is there much of a performance difference between the two code snippets:
void StdWithMutex( void )
{
std::ofstream outFile( "Test.tmp" );
std::lock_guard<std::mutex> lockGuard( m_mutex );
// Iterate through the data and write it to a file:
// m_setData is of type std::unordered_set<DataType>
for( auto data : m_setData )
{
outFile << data;
}
}
And:
void ConcRT( void )
{
std::ofstream outFile( "Test.tmp" );
// Iterate through the data and write it to a file:
// m_setData is of type concurrency::concurrent_unordered_set
for( auto data : m_setData )
{
outFile << data;
}
}
Moveover, I often need to print the data out in order, which is why I'm currently using std::set
as opposed to std::unordered_set
, so if there is a gain in using concurrency::concurrent_unordered_set
, would the potential performance gain come close to the cost of reordering the data each time it needs to be printed?