mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 22:02:49 -06:00
.tutorial
git-svn-id: svn://ultimatepp.org/upp/trunk@10557 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
639669d3de
commit
515af8ed37
9 changed files with 248 additions and 5 deletions
43
tutorial/CoreTutorial/CoWork.cpp
Normal file
43
tutorial/CoreTutorial/CoWork.cpp
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#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);
|
||||
|
||||
///
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue