Nautical bell: Difference between revisions
Content added Content deleted
(→{{header|D}}: updated output of test run) |
(→{{header|D}}: daemonize) |
||
Line 11: | Line 11: | ||
class NauticalBell : Thread { |
class NauticalBell : Thread { |
||
private bool stopped; |
private shared bool stopped; |
||
this() { |
this() { |
||
Line 34: | Line 34: | ||
if (next.minute == time.minute && |
if (next.minute == time.minute && |
||
next.hour == time.hour) { |
next.hour == time.hour) { |
||
immutable bells = |
immutable bells = numBells == 1 ? "bell" : "bells"; |
||
writefln("%s : %d %s |
writefln("%s : %d %s", time, numBells, bells); |
||
setNextBellTime(); |
setNextBellTime(); |
||
} |
} |
||
Line 43: | Line 43: | ||
} |
} |
||
void stop() |
void stop() { |
||
this.stopped = true; |
this.stopped = true; |
||
} |
} |
||
Line 50: | Line 50: | ||
void main() { |
void main() { |
||
auto bells = new NauticalBell(); |
auto bells = new NauticalBell(); |
||
bells.isDaemon(true); |
|||
bells.start(); |
bells.start(); |
||
try { |
|||
bells.join(); |
|||
} catch (ThreadException e) { |
|||
writeln(e.msg); |
|||
} |
|||
}</lang> |
}</lang> |
||
{{out}} |
{{out}} |