New member function wait that won't return until sampling is done.

This commit is contained in:
Ulrich Germann 2015-06-08 13:54:22 +01:00
parent ac99ec519f
commit 69f15d0c5a
2 changed files with 16 additions and 4 deletions

View File

@ -1,3 +1,4 @@
#include <boost/thread/locks.hpp>
#include "ug_bitext_pstats.h"
namespace Moses
@ -65,7 +66,7 @@ namespace Moses
bool
pstats::
add(uint64_t pid, float const w,
add(uint64_t pid, float const w, float const b,
vector<uchar> const& a,
uint32_t const cnt2,
uint32_t fwd_o,
@ -73,7 +74,7 @@ namespace Moses
{
boost::lock_guard<boost::mutex> guard(this->lock);
jstats& entry = this->trg[pid];
entry.add(w, a, cnt2, fwd_o, bwd_o, docid);
entry.add(w, b, a, cnt2, fwd_o, bwd_o, docid);
if (this->good < entry.rcnt())
{
UTIL_THROW(util::Exception, "more joint counts than good counts:"
@ -82,5 +83,14 @@ namespace Moses
return true;
}
void
pstats::
wait() const
{
boost::unique_lock<boost::mutex> lock(this->lock);
while (this->in_progress)
this->ready.wait(lock);
}
}
}

View File

@ -21,8 +21,8 @@ namespace Moses
#if UG_BITEXT_TRACK_ACTIVE_THREADS
static ThreadSafeCounter active;
#endif
boost::mutex lock; // for parallel gathering of stats
boost::condition_variable ready; // consumers can wait for me to be ready
mutable boost::mutex lock; // for parallel gathering of stats
mutable boost::condition_variable ready; // consumers can wait for me to be ready
size_t raw_cnt; // (approximate) raw occurrence count
size_t sample_cnt; // number of instances selected during sampling
@ -46,6 +46,7 @@ namespace Moses
bool
add(uint64_t const pid, // target phrase id
float const w, // sample weight (1./(# of phrases extractable))
float const b, // sample bias score
alnvec const& a, // local alignment
uint32_t const cnt2, // raw target phrase count
uint32_t fwd_o, // fwd. phrase orientation
@ -57,6 +58,7 @@ namespace Moses
size_t const num_pairs, // # of phrases extractable here
int const po_fwd, // fwd phrase orientation
int const po_bwd); // bwd phrase orientation
void wait() const;
};
}