1 // Written by Leandro Lucarella
3 // The goal of this program is to do very CPU intensive work in threads
5 import tango.core.Thread: Thread;
6 import tango.core.sync.Atomic: atomicStore, atomicLoad, atomicAdd;
7 import tango.io.device.File: File;
8 import tango.util.digest.Sha512: Sha512;
9 import tango.util.Convert: to;
14 int running; // Atomic
16 void main(char[][] args)
22 NT = to!(int)(args[2]);
24 N = to!(int)(args[1]);
26 atomicStore(running, NT);
27 BYTES = cast(ubyte[]) File.get(fname);
28 auto threads = new Thread[NT];
29 foreach(ref thread; threads) {
30 thread = new Thread(&doSha);
33 while (atomicLoad(running)) {
34 auto a = new void[](BYTES.length / 4);
35 a[] = cast(void[]) BYTES[];
38 foreach(thread; threads)
44 for (size_t i = 0; i < N; i++) {
45 auto sha = new Sha512;
48 atomicAdd(running, -1);