D Language 2.0
"Jérôme M. Berger"
jeberger at free.fr
Mon Jan 18 14:02:00 PST 2010
Andrei Alexandrescu wrote:
> Andrei Alexandrescu wrote:
>> Nick Sabalausky wrote:
>> [snip]
>>> It's been no worse at threading than C/C++ for quite some time. It's
>>> just starting to have a threading model that kicks the crap out of
>>> the threading in the vast majority of languages out there.
>>
>> BTW, that effort is going quite well. For example, a producer-consumer
>> file copy program using the proposed API has 20 lines, correctness and
>> all.
>>
>> import std.algorithm, std.concurrency, std.stdio;
>>
>> void main() {
>> enum bufferSize = 1024 * 100;
>> auto tid = spawn(&writer);
>> // Read loop
>> auto src = stdin.by!(ubyte)();
>> for (;;) {
>> auto buffer = UniqueArray!(ubyte)(bufferSize);
>> auto length = copy(take(src, bufferSize), buffer).length;
>> send(tid, move(buffer));
>> if (length == 0) break;
>> }
>> }
>>
>> void writer() {
>> // Write loop
>> auto tgt = stdout.by!(ubyte)();
>> for (;;) {
>> auto buffer = receiveOnly!(UniqueArray!ubyte)();
>> copy(buffer, tgt);
>> }
>> }
>>
>>
>> Andrei
>
> Sorry for the monologue. Actually I reworked the example into the even
> simpler:
>
> import std.concurrency, std.stdio;
>
> void main() {
> enum bufferSize = 1024 * 100;
> auto tid = spawn(&writer);
> // Read loop
> foreach (immutable(ubyte)[] buffer; stdin.byChunk(bufferSize)) {
> send(tid, buffer);
> }
> }
>
> void writer() {
> // Write loop
> for (;;) {
> auto buffer = receiveOnly!(immutable(ubyte)[])();
> tgt.rawWrite(buffer);
> }
> }
>
> We actually have implemented all the pieces to make this work.
>
Shouldn't you declare "tgt" somewhere (you did in your first example...
Jerome
--
mailto:jeberger at free.fr
http://jeberger.free.fr
Jabber: jeberger at jabber.fr
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: OpenPGP digital signature
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20100118/c6a217bb/attachment.pgp>
More information about the Digitalmars-d
mailing list