C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 1st, 2013, 09:18 AM
girijaram girijaram is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2013
Posts: 1 girijaram User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 31 sec
Reputation Power: 0
C++ mutlthreading synchronization issue

I have an issue with my code ... my below code is createing databases(database here is a kd tree) and indexing one image per database. i have two classes LastDatabaseTndexingPolicy and another forwardingDatabaseaccessor.cpp .

I am calling the GetDatabaseToAccess() function from forwardingDatabaseAccessor.cpp class .GetDatabaseToAccess() function is present in LastDatabaseTndexingPolicy class and it returns the database created as a pointer and using that database pointer we call another function which actually indexes the image to the database .

Now my issue is i am not able to have multiple threads act on the following functions as DatabaseAccessor_ptr db which is in the following file is coupled with two functions and however i put locks in the LastDatabaseTndexingPolicy file as below i end up getting synchronization issue ..........

Hence now i am using a single lock in forwardingDatabaseAccessor.cpp and serializing the code,.can anyone suggest me how can i change my design to parallelize this code .........

In ForwardingDatabaseAccessor.cpp we are calling function from LastDatabaseTndexingPolicy as shown below:-

DatabaseAccessor_ptr db is something which needs to be synchroinized. I tried createing 256 databases with one image each and when i run this code i ended up creating 175 databses and though i was restricting in code with locks that every database has only one image i ended up having two images in single database ..... ideally i had to get only one image per database but i got two images in few of them hence instead of 256 database this code created 175 or so databases.

indexing::IndexReturnValue ForwardDatabaseAccessor::index(cv::Mat image,
const std::string& imageName, features::Camera::Type indexCameraType,
features::Camera::Type recogCameraType) {
DatabaseAccessor_ptr db = this->IndexingPolicy_ptr->GetDBToIndex();

return db->index(image, imageName, indexCameraType, recogCameraType);
}


In file LastDatabaseTndexingPolicy we have this function GetDatabaseToIndex as follows:----


DatabaseAccessor_ptr LastDatabaseIndexingPolicy::GetDBToIndex()
{
int numDBs;
std::string db_Name;
size_t totNoOfIndexedImagesInDB;
DatabaseAccessor_ptr db;
std::vector<std::string>::iterator endIter;
{
READING_LOCK(lock, adbMutex);
numDBs = this->associateDBs->GetNumberOfAssociateDBs();
endIter = this->associateDBs->end();
endIter--;

}
if (numDBs == 0) {

std::string newDBName = this->CreateAssociateDBs(numDBs);
{
WRITING_LOCK(lock, dbMutex);
db = dbGroup.getDatabase(newDBName);
return db;
}

}

else {


WRITING_LOCK_ADV(writeLock, dbMutex);
totNoOfIndexedImagesInDB = dbGroup.getDatabase(*endIter)->size();
if (totNoOfIndexedImagesInDB >= (this->maxNumberOfImagesDBCFG))
{
writeLock.unlock();
std::string newDBName = this->CreateAssociateDBs(numDBs);
{
WRITING_LOCK(lock, dbMutex);
db = dbGroup.getDatabase(newDBName);
return db;
}
}
else
{

db = dbGroup.getDatabase(*endIter);
return db;
writeLock.unlock();

}
return db;
}
}






std::string IndexToLastDB::CreateAssociateDBs(int numDB) {



std:stringstream convert;
convert << (numDB + 1);
std::string newDBName = this->dbName + "_server_fwd_" + convert.str();
std::string db_properties = "type=ripe";
LOG(info,dbName) << "Name of the new database: " << newDBName;
{
WRITING_LOCK(lock, dbMutex);
dbGroup.createDatabase(newDBName, db_properties);
}

{
WRITING_LOCK(lock, adbMutex);
this->associateDBs->AddAssociateDB(newDBName);
}
{
WRITING_LOCK(fileLock, fileMutex);
util::serialization::save<indexing::forward::AssociateDBCollection>(
*this->associateDBs, dbFile.string(), serializationFormat);
}

return newDBName;

}

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > C++ mutlthreading synchronization issue


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap