Sender: |
|
Date: |
Sat, 20 Jun 2015 11:25:05 -0400 |
Reply-To: |
|
Subject: |
|
MIME-Version: |
1.0 |
Message-ID: |
|
In-Reply-To: |
|
Content-Type: |
multipart/alternative; boundary=089e0141a8dc2479300518f4a522 |
From: |
|
Parts/Attachments: |
|
|
Static variables are shared between threads. Don't make your
thread-specific data static.
"Are there some issues when different threads try to read/write into the
same variable?"
Yes, it can get very tricky if writing is involved. For instance, while
different threads can read/write to the same static variable, the changes
might not become visible to other threads immediately due to how caching
works. See
http://stackoverflow.com/questions/4934913/are-static-variables-shared-between-threads
Avoid it entirely when you can.
Siggy
On Jun 20, 2015 5:00 AM, "Axel Kowald" <[log in to unmask]> wrote:
> Hi,
>
> While the hand-coded versions of the top-level loop do indeed reuse the
>> same SimState, this is not the case for doLoop. There's a good reason for
>> this: one of the things doLoop can do is run your N jobs in *parallel*, not
>> just in serial.
>>
> thanks for the information.
> I decided to use the doLoop and collect my data in static class variables.
> Because that worked fine I'm now also trying to use the -parallel option.
> It seems that my static variable is filled from all parallel batches. How
> is this possible if all batches run in independent threads? Are there some
> issues when different threads try to read/write into the same variable?
> I'm normally not using parallel stuff, so please excuse if this is trivial.
>
> Many thanks,
> Axel
>
|
|
|