void ScrAddrFilter::scanScrAddrMapInNewThread()
{
   auto scanMethod = [this](void)->void
   { this->scanScrAddrThread(); };

   thread scanThread(scanMethod);
   scanThread.detach();
}
Esempio n. 2
0
void scanThreads() {
    Thread *thread;

    pthread_mutex_lock(&lock);
    for(thread = &main_thread; thread != NULL; thread = thread->next)
        scanThread(thread);
    pthread_mutex_unlock(&lock);
}
Esempio n. 3
0
// Test if we can read and write from multiple threads without failures
TEST_P(BufferTest, MultiThreadScanAndWrite)
{
	// Start scan thread
	bool stop = false;
	uint32_t fails = 0;
	std::thread scanThread( Scan, mgr, GetParam().pagesOnDisk, std::ref(stop), std::ref(fails) );

	// Start read/write threads
	std::vector<std::future<uint32_t>> readWriteFutures;
	for ( uint32_t i = 0; i < GetParam().threads; i++ )
	{
		readWriteFutures.push_back( std::async( ReadWrite, mgr, i, 
												GetParam().threads, GetParam().pagesOnDisk ) );
	}

	// Wait for read/write threads
	uint32_t totalCount = 0;
	for ( uint32_t i = 0; i < GetParam().threads; i++ )
	{
		totalCount += readWriteFutures[i].get();
	}

	// Wait for scan thread
	stop = true;
	scanThread.join();
	EXPECT_EQ( 0, fails );

	// Restart buffer manager
	SDELETE(mgr);
	mgr = new BufferManager( GetParam().pagesInMemory );

	// Verify results
	uint32_t totalCountOnDisk = 0;
	for ( uint32_t i = 0; i < GetParam().pagesOnDisk; i++ )
	{
		BufferFrame& bf = mgr->FixPage( BufferManager::MergePageId( DB_TEST_SEGMENT, i ), false );
		totalCountOnDisk += reinterpret_cast<uint32_t*>(bf.GetData())[0];
		mgr->UnfixPage( bf, false );
	}
	EXPECT_EQ( totalCount, totalCountOnDisk );
}