-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfutter.cpp
More file actions
65 lines (50 loc) · 1.37 KB
/
futter.cpp
File metadata and controls
65 lines (50 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <futter.h>
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <stdio.h>
#include <sys/stat.h>
futtern::futtern()
{
lock=false;
semaphore="data/semaphore.dat";
}
futtern::~futtern()
{
}
void futtern::erzeuge_futter()
{
warte_auf_futter(semaphore);
fstream f;
string s="data/futter.dat";
f.open(s.c_str(),ios::out | ios::trunc);
futtern::futter.serialize(f);
f.close();
remove(semaphore);
}
void futtern::hole_futter ()
{
warte_auf_futter(semaphore);
ifstream f;
string s="data/futter.dat";
f.open(s.c_str(),ios::in );
futtern::futter.deserialize(f);
f.close();
remove(semaphore);
}
bool futtern::exists (const std::string& name) {
struct stat buffer;
return (stat (name.c_str(), &buffer) == 0);
}
void futtern::warte_auf_futter(const std::string& name)
{
while (exists(semaphore)) //So lange die Semaphore existiert warten
{
usleep (std::rand()%100); //Immer verschieden lang warten..
}
fstream f;
string s=semaphore;
f.open(s.c_str(),ios::out | ios::trunc);
futtern::futter.serialize(f);
f.close();
}