parallel processing - C# parallelism in LINQ -


i know if safe way of calculating x in code below.

public static ienumerable<object> parse(object obj, ref int x) {     x += 10;     return new list<object>(); }  public static void query(list<object> obj) {     int x = 0;      var result = obj         .asparallel()         .select(o => parse(o, ref x))         .aggregate((a, b) => a.concat(b)); } 

this shortened version of code. want x kind of static counter parallel executions of parse. hope not confusing.

definitely not safe. need use interlocked class.

public static ienumerable<object> parse(object obj, ref int x) {     interlocked.add(ref x, 10);     return new list<object>(); } 

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -