make fuzzy match pt threadable by marking it as non-threadable! TODO - do it properly

This commit is contained in:
Hieu Hoang 2012-11-23 18:52:06 +00:00
parent cb95548871
commit 7b36e11276
5 changed files with 30 additions and 8 deletions

View File

@ -43,7 +43,7 @@ const Factor *FactorCollection::AddFactor(const StringPiece &factorString)
FactorFriend to_ins;
to_ins.in.m_string.assign(factorString.data(), factorString.size());
#endif // BOOST_VERSION
{
{ // read=lock scope
boost::shared_lock<boost::shared_mutex> read_lock(m_accessLock);
#if BOOST_VERSION >= 104200
// If this line doesn't compile, upgrade your Boost.

View File

@ -77,10 +77,10 @@ PhraseDictionaryFeature::PhraseDictionaryFeature
m_sparsePhraseDictionaryFeature(spdf)
{
if (implementation == Memory || implementation == SCFG || implementation == SuffixArray ||
implementation==Compact ) {
implementation==Compact) { // || implementation==FuzzyMatch ) {
m_useThreadSafePhraseDictionary = true;
if (implementation == SuffixArray) {
cerr << "Warning: implementation holds chached weights!" << endl;
cerr << "Warning: implementation holds cached weights!" << endl;
exit(1);
}
} else {

View File

@ -29,7 +29,6 @@ public:
protected:
// tm-mt
//std::vector< std::vector< tmmt::WORD_ID > > source;
std::vector< std::vector< tmmt::SentenceAlignment > > targetAndAlignment;
tmmt::SuffixArray *suffixArray;
std::map< WORD_ID,std::vector< int > > single_word_index;

View File

@ -1,5 +1,8 @@
// $Id: Vocabulary.cpp 1565 2008-02-22 14:42:01Z bojar $
#include "Vocabulary.h"
#ifdef WITH_THREADS
#include <boost/thread/locks.hpp>
#endif
using namespace std;
@ -30,11 +33,17 @@ vector<WORD_ID> Vocabulary::Tokenize( const char input[] ) {
}
WORD_ID Vocabulary::StoreIfNew( const WORD& word ) {
map<WORD, WORD_ID>::iterator i = lookup.find( word );
if( i != lookup.end() )
return i->second;
{ // read=lock scope
boost::shared_lock<boost::shared_mutex> read_lock(m_accessLock);
map<WORD, WORD_ID>::iterator i = lookup.find( word );
if( i != lookup.end() )
return i->second;
}
boost::unique_lock<boost::shared_mutex> lock(m_accessLock);
WORD_ID id = vocab.size();
vocab.push_back( word );
lookup[ word ] = id;
@ -42,6 +51,8 @@ WORD_ID Vocabulary::StoreIfNew( const WORD& word ) {
}
WORD_ID Vocabulary::GetWordID( const WORD &word ) {
boost::shared_lock<boost::shared_mutex> read_lock(m_accessLock);
map<WORD, WORD_ID>::iterator i = lookup.find( word );
if( i == lookup.end() )
return 0;

View File

@ -11,6 +11,10 @@
#include <map>
#include <cmath>
#ifdef WITH_THREADS
#include <boost/thread/shared_mutex.hpp>
#endif
namespace tmmt
{
@ -38,6 +42,14 @@ class Vocabulary {
WORD_ID GetWordID( const WORD& );
std::vector<WORD_ID> Tokenize( const char[] );
inline WORD &GetWord( WORD_ID id ) const { WORD &i = (WORD&) vocab[ id ]; return i; }
protected:
#ifdef WITH_THREADS
//reader-writer lock
mutable boost::shared_mutex m_accessLock;
#endif
};
}