Skip to content

Commit

Permalink
Remove trailing spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Feb 24, 2013
1 parent 651f09f commit b08ffbd
Showing 1 changed file with 42 additions and 42 deletions.
84 changes: 42 additions & 42 deletions std/parallelism.d
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ Synopsis:
import std.algorithm, std.parallelism, std.range;
void main() {
// Parallel reduce can be combined with
// std.algorithm.map to interesting effect.
// The following example (thanks to Russel Winder)
// calculates pi by quadrature using
// Parallel reduce can be combined with
// std.algorithm.map to interesting effect.
// The following example (thanks to Russel Winder)
// calculates pi by quadrature using
// std.algorithm.map and TaskPool.reduce.
// getTerm is evaluated in parallel as needed by
// getTerm is evaluated in parallel as needed by
// TaskPool.reduce.
//
// Timings on an Athlon 64 X2 dual core machine:
Expand Down Expand Up @@ -793,7 +793,7 @@ import std.file;
void main()
{
// Create and execute a Task for reading
// Create and execute a Task for reading
// foo.txt.
auto file1Task = task!read("foo.txt");
file1Task.executeInNewThread();
Expand All @@ -808,10 +808,10 @@ void main()
---
// Sorts an array using a parallel quick sort algorithm.
// The first partition is done serially. Both recursion
// The first partition is done serially. Both recursion
// branches are then executed in parallel.
//
// Timings for sorting an array of 1,000,000 doubles on
// Timings for sorting an array of 1,000,000 doubles on
// an Athlon 64 X2 dual core machine:
//
// This implementation: 176 milliseconds.
Expand Down Expand Up @@ -855,14 +855,14 @@ class/struct with overloaded opCall.
Examples:
---
// Read two files in at the same time again,
// but this time use a function pointer instead
// Read two files in at the same time again,
// but this time use a function pointer instead
// of an alias to represent std.file.read.
import std.file;
void main()
{
// Create and execute a Task for reading
// Create and execute a Task for reading
// foo.txt.
auto file1Task = task(&read, "foo.txt");
file1Task.executeInNewThread();
Expand Down Expand Up @@ -1100,7 +1100,7 @@ private:

// This function performs initialization for each thread that affects
// thread local storage and therefore must be done from within the
// worker thread. It then calls executeWorkLoop().
// worker thread. It then calls executeWorkLoop().
void startWorkLoop()
{
// Initialize thread index.
Expand All @@ -1110,15 +1110,15 @@ private:
threadIndex = nextThreadIndex;
nextThreadIndex++;
}

executeWorkLoop();
}

// This is the main work loop that worker threads spend their time in
// until they terminate. It's also entered by non-worker threads when
// finish() is called with the blocking variable set to true.
void executeWorkLoop()
{
{
while(atomicReadUbyte(status) != PoolState.stopNow)
{
AbstractTask* task = pop();
Expand Down Expand Up @@ -1188,7 +1188,7 @@ private:
void abstractPut(AbstractTask* task)
{
queueLock();
scope(exit) queueUnlock();
scope(exit) queueUnlock();
abstractPutNoSync(task);
}

Expand Down Expand Up @@ -1217,7 +1217,7 @@ private:
"finish() or stop()."
);
}

task.next = null;
if (head is null) //Queue is empty.
{
Expand All @@ -1243,7 +1243,7 @@ private:
"finish() or stop()."
);
}

if(head is null)
{
head = h;
Expand Down Expand Up @@ -1790,9 +1790,9 @@ public:
Examples:
---
// Pipeline reading a file, converting each line
// to a number, taking the logarithms of the numbers,
// and performing the additions necessary to find
// Pipeline reading a file, converting each line
// to a number, taking the logarithms of the numbers,
// and performing the additions necessary to find
// the sum of the logarithms.
auto lineRange = File("numberList.txt").byLine();
Expand Down Expand Up @@ -2301,8 +2301,8 @@ public:
Examples:
---
// Fetch lines of a file in a background
// thread while processing prevously fetched
// Fetch lines of a file in a background
// thread while processing prevously fetched
// lines, without duplicating any lines.
auto file = File("foo.txt");
Expand All @@ -2311,8 +2311,8 @@ public:
file.readln(buf);
}
// Fetch more lines in the background while we
// process the lines already read into memory
// Fetch more lines in the background while we
// process the lines already read into memory
// into a matrix of doubles.
double[][] matrix;
auto asyncReader = taskPool.asyncBuf(&next, &file.eof);
Expand Down Expand Up @@ -2380,7 +2380,7 @@ public:
those generated by $(XREF algorithm, _reduce) or depending on how many work
units are used. The next argument must be the range to be reduced.
---
// Find the sum of squares of a range in parallel, using
// Find the sum of squares of a range in parallel, using
// an explicit seed.
//
// Timings on an Athlon 64 X2 dual core machine:
Expand All @@ -2397,7 +2397,7 @@ public:
is used as a seed. For the final reduction, the result from the first
work unit is used as the seed.
---
// Find the sum of a range in parallel, using the first
// Find the sum of a range in parallel, using the first
// element of each work unit as the seed.
auto sum = taskPool.reduce!"a + b"(nums);
---
Expand Down Expand Up @@ -2740,10 +2740,10 @@ public:
Examples:
---
// Execute a loop that computes the greatest common
// divisor of every number from 0 through 999 with
// Execute a loop that computes the greatest common
// divisor of every number from 0 through 999 with
// 42 in parallel. Write the results out to
// a set of files, one for each thread. This allows
// a set of files, one for each thread. This allows
// results to be written out without any synchronization.
import std.conv, std.range, std.numeric, std.stdio;
Expand Down Expand Up @@ -3109,10 +3109,10 @@ public:
before returning. This option might be used in applications where
task results are never consumed-- e.g. when $(D TaskPool) is employed as a
rudimentary scheduler for tasks which communicate by means other than
return values.
return values.
Warning: Calling this function with $(D blocking = true) from a worker
thread that is a member of the same $(D TaskPool) that
thread that is a member of the same $(D TaskPool) that
$(D finish) is being called on will result in a deadlock.
*/
void finish(bool blocking = false) @trusted
Expand All @@ -3123,23 +3123,23 @@ public:
atomicCasUbyte(status, PoolState.running, PoolState.finishing);
notifyAll();
}
if (blocking)
if (blocking)
{
// Use this thread as a worker until everything is finished.
executeWorkLoop();
foreach(t; pool)

foreach(t; pool)
{
// Maybe there should be something here to prevent a thread
// from calling join() on itself if this function is called
// from a worker thread in the same pool, but:
//
// 1. Using an if statement to skip join() would result in
// 1. Using an if statement to skip join() would result in
// finish() returning without all tasks being finished.
//
// 2. If an exception were thrown, it would bubble up to the
// Task from which finish() was called and likely be
// swallowed.
// swallowed.
t.join();
}
}
Expand Down Expand Up @@ -3333,8 +3333,8 @@ readable.
Example:
---
// Find the logarithm of every number from
// 1 to 1_000_000 in parallel, using the
// Find the logarithm of every number from
// 1 to 1_000_000 in parallel, using the
// default TaskPool instance.
auto logs = new double[1_000_000];
Expand Down Expand Up @@ -4117,7 +4117,7 @@ unittest
pool1.put(tSlow);
pool1.finish();
tSlow.yieldForce();
// Can't assert that pool1.status == PoolState.stopNow because status
// Can't assert that pool1.status == PoolState.stopNow because status
// doesn't change until after the "done" flag is set and the waiting
// thread is woken up.

Expand All @@ -4126,14 +4126,14 @@ unittest
pool2.put(tSlow2);
pool2.finish(true); // blocking
assert(tSlow2.done);

// Test fix for Bug 8582 by making pool size zero.
auto pool3 = new TaskPool(0);
auto tSlow3 = task!slowFun();
pool3.put(tSlow3);
pool3.finish(true); // blocking
assert(tSlow3.done);

// This is correct because no thread will terminate unless pool2.status
// and pool3.status have already been set to stopNow.
assert(pool2.status == TaskPool.PoolState.stopNow);
Expand Down

0 comments on commit b08ffbd

Please sign in to comment.