On 6/20/20 9:30 AM, adnan338 wrote:

> Hello, I need a code review on my strategy

I don't know gtkd so I did not compile the code and I did not review the code very carefully.

However, I don't think you need to 'synchronized' the whole parallel loop. Since there is only one thread that executes start(), that synchronized cannot have any effect at all. What you want to synchronize is the mutating access to 'completed' by the threads that parallel() starts automatically. So, move 'synchronized' just around that expression:

// REMOVE this one:
// synchronized
// {

  foreach (_; downloader.links.parallel())
  {
      Thread.sleep(uniform(0, 6, rnd).seconds());

      // ADD this one:
      synchronized {
        ++cast() downloader.completed;
      }
  }

// }

Ali

Reply via email to