How can we help you today? How can we help you today?

TPL Parellel.ForWorker<T> completely broken

in the task parallel library System.Threading.dll, Parallel.ForWorker i got this piece of code disassembled:

using (Task task = Task.Create(delegate {
int num1int num3int num2 = base.stepdo {
num1 = base.sharedIndexnum3 = num1 + num2if (num3 < num1)
{
num3 = 2147483647}
}
while (Interlocked.CompareExchange(ref sharedIndex, num3, num1) != num1);

as you can see the syntax is unreadable.

optimization: .net 3.5
reflector: free 5.1.3.0
xor88
0

Comments

3 comments

  • Noblebug
    There is no such library System.Threading.dll in .Net framework from Microsoft. System.Threading is a namespace in mscorlib.dll. I have not found Parallel class in mscorlib.dll. What version of .Net framework which is installed in your system?
    Noblebug
    0
  • Bart Read
    I think this is an experimental thing, however, you might try View > Options, and then switch "Optimization" to ".NET 3.5" to see if that makes any difference.

    Hope that helps.


    Thanks,


    Bart
    Bart Read
    0
  • odalet
    In fact, the result is (a little bit) better if you revert to .NET 1.0 optimizations. This way, Reflector won't try to display anonymous delegates and will revert to a .NET 1.0 syntax, (with inner classes). But because these classes are generated, their name isn't C# compliant and it won't compile. In these sort of case, I use global renamings (replacing each invalid character in a name by an underscore, and hopping I won't have collisions).

    For instance here the same piece of code with .NET 1.0 optimization:
    using &#40;Task task = Task.Create&#40;new Action&lt;object&gt;&#40;class2.&lt;ForWorker&gt;b__3&#41;, manager, options | TaskCreationOptions.SelfReplicating&#41;&#41;
            &#123;
                task.Wait&#40;&#41;;
            &#125;
    

    And if you go to the <ForWorker>b__3 method, you can see this:
        int sharedIndex;
        int num3;
        int step = this.step;
        do
        &#123;
            sharedIndex = this.sharedIndex;
            num3 = sharedIndex + step;
            if &#40;num3 &lt; sharedIndex&#41;
            &#123;
                num3 = 0x7fffffff;
            &#125;
        &#125;
    

    Better, isn't it?

    And for information, System.Threading.dll is new and not yet RTM, but so useful! It is the new Microsoft Parallel extensions for .NET

    Download it here: http://www.microsoft.com/downloads/deta ... laylang=en
    odalet
    0

Add comment

Please sign in to leave a comment.