ultimatepp/tutorial/CoreTutorial/CoWork.cpp
cxl 515af8ed37 .tutorial
git-svn-id: svn://ultimatepp.org/upp/trunk@10557 f0d560ea-af0d-0410-9eb7-867de7ffcac7
2016-12-19 14:32:40 +00:00

43 lines
819 B
C++

#include "Tutorial.h"
void CoWorkTutorial()
{
/// .`CoWork`
FileIn in(GetDataFile("test.txt")); // let us open some tutorial testing data
Index<String> w;
Mutex m; // need mutex to serialize access to w
CoWork co;
while(!in.IsEof()) {
String ln = in.GetLine();
co & [ln, &w, &m] {
for(const auto& s : Split(ln, [](int c) { return IsAlpha(c) ? 0 : c; })) {
Mutex::Lock __(m);
w.FindAdd(s);
}
};
}
co.Finish();
DUMP(w);
///
in.Seek(0);
while(!in.IsEof()) {
String ln = in.GetLine();
co & [ln, &w, &m] {
Vector<String> h = Split(ln, [](int c) { return IsAlpha(c) ? 0 : c; });
CoWork::FinLock(); // replaces the mutex, locked till the end of CoWork job
for(const auto& s : h)
w.FindAdd(s);
};
}
DUMP(w);
///
}