Concurrency and parallelism may be emphasized well with this simple example:

    foreach(i, ref elem; task_pool.parallel(logs)) {
        elem = log(i + 1.0);
    }

Keeping the (straight forward) serial semantics, we write parallelizable code.

Another good example, that demonstrates concurrency model borrowed from Erlang is:

    while (cont) {
        receive(
            (int msg) { writeln("int received: ", msg) },
            (string msg) {
                cont = (msg == "stop") ? false : true;
            }
        );
    }

The 'send' part you can easily add by yourself.

Both examples emphasize requiring little and giving much.

Reply via email to