[Issue 2043] Closure outer variables in nested blocks are not allocated/instantiated correctly.
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Tue Jul 15 09:09:12 PDT 2014
https://issues.dlang.org/show_bug.cgi?id=2043
Artem Borisovskiy <kolos80 at bk.ru> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |kolos80 at bk.ru
Severity|normal |major
--- Comment #9 from Artem Borisovskiy <kolos80 at bk.ru> ---
I write a simple app that reads a binary log file, decrypts the messages in
parrallel and prints them when all the decrypting threads are finished. Here's
a piece of my code:
--------------
auto workers = new ThreadGroup;
int i;
foreach (group; logEntries.chunks(averageChunkSize)) () {
auto data = group;
auto ii = i;
auto workerThread = new Thread(
{
writefln("[%s] %s", ii, data.length);
});
workers.add(workerThread);
workerThread.start;
++i;
}();
workers.joinAll;
--------------
As you can see, I tried to use hack from the code above, but it didn't help
until I created "data" and "ii" variables. Just using "i" and "group" gives
wrong results, just as described by Bruno. The same code works perfectly in
Java, and it should in D, because it's the way closures work.
Please, fix this bug, it's real PITA and it's 6 years old after all.
--
More information about the Digitalmars-d-bugs
mailing list