This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main(string[] args) | |
{ | |
struct Foo(float f) { | |
alias VAL = f; | |
float getF() { | |
return f; | |
} | |
} | |
Foo!(float.nan) f; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main(string[] args) | |
{ | |
// Check for valid arguments | |
enforce(args.length == 3); | |
int numPeople = to!int(args[1]); | |
int numNutrients = to!int(args[2]); | |
StopWatch sw; | |
// Time feeding with threads | |
sw.start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void feedWithFibers(int numPeople, int numNutrients) | |
{ | |
size_t terminated; | |
auto fibers = new FeedFiber[numPeople]; | |
foreach (ref f; fibers) | |
{ | |
f = new FeedFiber(new Person(numNutrients)); | |
} | |
while (terminated != fibers.length) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FeedFiber : Fiber | |
{ | |
Person mPerson; | |
this(Person p) | |
{ | |
mPerson = p; | |
super(&run); | |
} | |
void run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person | |
{ | |
struct Nutrients | |
{ | |
int Fiber; | |
int Calcium; | |
int Iron; | |
} | |
int mNumNutrients; | |
Nutrients mNutrients; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variable amountOfBreathToTake; | |
function breathe() | |
{ | |
do | |
breathe amountOfBreathToTake; | |
amountOfBreathToTake = 0; | |
Fiber.yield(); | |
while alive; | |
} | |
function walk() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variable amountOfBreathToTake; | |
function breathe() | |
{ | |
do | |
breathe amountOfBreathToTake; | |
amountOfBreathToTake = 0; | |
while alive; | |
} | |
function walk() | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a thread for both tasks so they can execute at once | |
breathingThread = new Thread(breathe); | |
walkingThread = new Thread(walk); | |
// Start doing both of the tasks at the same time | |
breathingThread.start(); | |
walkingThread.start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function breathe() | |
{ | |
// We have to breathe to survive | |
} | |
function walk() | |
{ | |
// I need to get somewhere | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright Robert Clipsham 2011. | |
// Distributed under the Boost Software License, Version 1.0. | |
// (See accompanying file LICENSE_1_0.txt or copy at | |
// http://www.boost.org/LICENSE_1_0.txt) | |
module main; | |
import core.thread; | |
import std.conv; | |
import std.datetime; |