Click here to Skip to main content
15,886,016 members

Comments by myker (Top 5 by date)

myker 9-Sep-11 18:25pm View    
Deleted
After running tests, I have to conclude that Richard is correct... The AsParallel() apples to the OrderBy clause, thereby invoking the Random class in a non-threadsafe way. This doesn't noticably affect the outcome, as the orderby clause shuffles position and the results are random enough. That said, it's still bad practice, and a good parallelization solution for using Random can be found here: http://www.albahari.com/threading/part5.aspx under the section entitled "Using ThreadLocal<T>"
myker 9-Sep-11 17:51pm View    
Deleted
Richard... after further investigation, the AsParallel() is applied to Range(), which generates a range of numbers and appears to be thread safe. The OrderBy, which is where the Random function is used, is resolved with each enumeration, and not in parallel. Though, this is still useful knowledge because the programmer should keep this in mind and not enumerate the result using the Parallel library.

As I understand it, OrderBy needs a fully enumerated result set in order to work, so it blocks until Range is completed, which is where the AsParallel is being applied.

Please, anyone out there, correct me if I am misunderstanding this.
myker 9-Sep-11 17:40pm View    
Deleted
Good catch, Richard! That's really good to know. I'm removing the "AsParallel" from the alternative.
myker 2-Sep-11 11:12am View    
Deleted
I'm not sure I understand your comment. Can you explain further?
myker 1-Sep-11 23:30pm View    
Deleted
Thank you! Glad to be of some help.