WaitAll problem

Jul 27, 2011 at 5:03 PM

Hello,

Here is the code I use in WP7:

System.Diagnostics.Debug.WriteLine("begin waitall");

            PortableTPL.Task task0 = PortableTPL.Task.Factory.StartNew(() =>
            {
                PortableTPL.Task task1 = PortableTPL.Task.Factory.StartNew(() =>
                {
                    System.Diagnostics.Debug.WriteLine("task1");
                    });

                PortableTPL.Task task2 = PortableTPL.Task.Factory.StartNew(() =>
                {
                    System.Diagnostics.Debug.WriteLine("task2");
                    });

                List<PortableTPL.Task> tasks = new List<PortableTPL.Task>() { task1, task2 };
                PortableTPL.Task.WaitAll(tasks.ToArray());
                
            });
            System.Diagnostics.Debug.WriteLine("waitall"); 
If I remove task0, all is working properly on the main thread.
But if task1 and task2 are running on task0, task0 doesn't wait which is the problem.
Could you help me ? I would like task0 to wait task1 and task2.Maybe I use a wrong way to achieve this.
Thanks in advance for your help.
Coordinator
Jul 28, 2011 at 9:48 AM

Hi!

Alas, the last release of the Portable Library removed support for Thread.

So I must stop the development of PortableTPL for now :(

Jul 29, 2011 at 5:02 PM

Hello again and sorry to tell that it is probably a "major bug" in PortableTPL.

As you know in WP7, there is the UI thread, the compositor thread (the developer can't use it, I hope to be able to convolute bitmaps faster with it soon) and Microsoft gives the developers 2 threads in an application.

As I said if the code runs on the UI thread, no problem, the result displayed is:

begin waitall

idui:235864114

idtask0:235864114

test

task2

idtask2:264634426

task1

idtask1:253689914

test2

waitall

Task1 and Task2 are running on 2 new threads, but if I run the same code on Task0, Wp7 UI thread creates the task0 thread . The problem occurs now:

Wp7 must run 2 Tasks with only 1 thread left. To do so, in my custom test, Wp7 reuse task0 thread to execute task1 and starts the last thread available to execute task2.

The result with PortableTPL is : task0 thread = task1thread , so waitall asks task0 thread to wait for thread task1 and thread task2, but since thread task0 = thread task1, task1 WaitEvent(manualresetevent) is never set and task0 is waiting for continously.

The bug can be reproduced easily in WP7 emulator because of the 2 threads limitations available in an app.

Since Silverlight or XBox360 can run more threads, this bug occurs only in few cases, but can result in data corruptions too.

Today, I think it is a limitation in WP7 and I recommend to run a task only on the UI thread and not inside another task or you will probably loose one thread or more (and there is no timeout to reset the thread lost).

I hope you will answer me I'm making a big mistake or you will find a solution to the problem.

Coordinator
Jul 29, 2011 at 5:28 PM

Hi alphapager,,

I can debug but I need your help :^) Can you send me your portable library installation? (mine doesn’t have threadsL)

From: alphapager [email removed]
Sent: vendredi 29 juillet 2011 19:03
To: david.catuhe@live.fr
Subject: Re: WaitAll problem [portabletpl:266751]

From: alphapager

Hello again and sorry to tell that it is probably a "major bug" in PortableTPL.

As you know in WP7, there is the UI thread, the compositor thread (the developer can't use it, I hope to be able to convolute bitmaps faster with it soon) and Microsoft gives the developers 2 threads in an application.

As I said if the code runs on the UI thread, no problem, the result displayed is:

begin waitall

idui:235864114

idtask0:235864114

test

task2

idtask2:264634426

task1

idtask1:253689914

test2

waitall

Task1 and Task2 are running on 2 new threads, but if I run the same code on Task0, Wp7 UI thread creates the task0 thread . The problem occurs now:

Wp7 must run 2 Tasks with only 1 thread left. To do so, in my custom test, Wp7 reuse task0 thread to execute task1 and starts the last thread available to execute task2.

The result with PortableTPL is : task0 thread = task1thread , so waitall asks task0 thread to wait for thread task1 and thread task2, but since thread task0 = thread task1, task1 WaitEvent(manualresetevent) is never set and task0 is waiting for continously.

The bug can be reproduced easily in WP7 emulator because of the 2 threads limitations available in an app.

Since Silverlight or XBox360 can run more threads, this bug occurs only in few cases, but can result in data corruptions too.

Today, I think it is a limitation in WP7 and I recommend to run a task only on the UI thread and not inside another task or you will probably loose one thread or more (and there is no timeout to reset the thread lost).

I hope you will answer me I'm making a big mistake or you will find a solution to the problem.

Jul 29, 2011 at 6:43 PM

I don't use the portable library Delta.

I use the PotableTPL.dll in my test phone app and the the thread id running inside all tasks like this:

System.Diagnostics.Debug.WriteLine("idtask2:" + System.Threading.Thread.CurrentThread.ManagedThreadId);

I don't know how to do with portable library but I will investigate.

Hope this helps.

Coordinator
Jul 29, 2011 at 6:50 PM

Can you send me the dll?

I will try with itJ

From: alphapager [email removed]
Sent: vendredi 29 juillet 2011 20:44
To: david.catuhe@live.fr
Subject: Re: WaitAll problem [portabletpl:266751]

From: alphapager

I don't use the portable library Delta.

I use the PotableTPL.dll in my test phone app and the the thread id running inside all tasks like this:

System.Diagnostics.Debug.WriteLine("idtask2:" + System.Threading.Thread.CurrentThread.ManagedThreadId);

I don't know how to do with portable library but I will investigate.

Hope this helps.

Jul 29, 2011 at 7:18 PM

I sent you the project, but I use Visual Studio 2010 for Mango beta2, but the project is running under Wp7 7.0.

If you can't open the solution, you will have to add the files manually.

Coordinator
Jul 30, 2011 at 7:18 AM

Arfff L

You’re totally right!

It’s a major bug and the only solution I see for now, is to limit the launch of task to the UI thread only L

From: alphapager [email removed]
Sent: vendredi 29 juillet 2011 19:03
To: david.catuhe@live.fr
Subject: Re: WaitAll problem [portabletpl:266751]

From: alphapager

Hello again and sorry to tell that it is probably a "major bug" in PortableTPL.

As you know in WP7, there is the UI thread, the compositor thread (the developer can't use it, I hope to be able to convolute bitmaps faster with it soon) and Microsoft gives the developers 2 threads in an application.

As I said if the code runs on the UI thread, no problem, the result displayed is:

begin waitall

idui:235864114

idtask0:235864114

test

task2

idtask2:264634426

task1

idtask1:253689914

test2

waitall

Task1 and Task2 are running on 2 new threads, but if I run the same code on Task0, Wp7 UI thread creates the task0 thread . The problem occurs now:

Wp7 must run 2 Tasks with only 1 thread left. To do so, in my custom test, Wp7 reuse task0 thread to execute task1 and starts the last thread available to execute task2.

The result with PortableTPL is : task0 thread = task1thread , so waitall asks task0 thread to wait for thread task1 and thread task2, but since thread task0 = thread task1, task1 WaitEvent(manualresetevent) is never set and task0 is waiting for continously.

The bug can be reproduced easily in WP7 emulator because of the 2 threads limitations available in an app.

Since Silverlight or XBox360 can run more threads, this bug occurs only in few cases, but can result in data corruptions too.

Today, I think it is a limitation in WP7 and I recommend to run a task only on the UI thread and not inside another task or you will probably loose one thread or more (and there is no timeout to reset the thread lost).

I hope you will answer me I'm making a big mistake or you will find a solution to the problem.