tasks a-s

This commit is contained in:
Ingy döt Net 2013-04-10 23:57:08 -07:00
parent 47bf37c096
commit b83f433714
12433 changed files with 156208 additions and 123 deletions

View file

@ -0,0 +1,50 @@
import std.stdio, core.thread, std.datetime;
class NauticalBell : Thread {
private shared bool stopped;
this() {
super(&run);
}
void run() {
uint numBells;
auto time = cast(TimeOfDay)Clock.currTime();
auto next = TimeOfDay();
void setNextBellTime() {
next += minutes(30);
numBells = 1 + (numBells % 8);
}
while (next < time)
setNextBellTime();
while (!this.stopped) {
time = cast(TimeOfDay)Clock.currTime();
if (next.minute == time.minute &&
next.hour == time.hour) {
immutable bells = numBells == 1 ? "bell" : "bells";
writefln("%s : %d %s", time, numBells, bells);
setNextBellTime();
}
sleep(dur!"msecs"(100));
yield();
}
}
void stop() {
this.stopped = true;
}
}
void main() {
auto bells = new NauticalBell();
bells.isDaemon(true);
bells.start();
try {
bells.join();
} catch (ThreadException e) {
writeln(e.msg);
}
}