This project is read-only.

Threadpool on Xbox360 -> Error 3

Oct 19, 2010 at 5:38 AM
Edited Oct 19, 2010 at 5:41 AM

I love the framework so I just wanted to point out a bug in the threadpool class when running on the xbox 360 and possibly the windows phone. It happens when a lot of tasks are added to the pool in quick succession.

A project illustrating the error can be downloaded here at the official xna forums: http://forums.create.msdn.com/forums/t/62991.aspx

Oct 19, 2010 at 10:38 AM

Yikes! That's one ugly bug.

I'm looking for it now, will report back when I have it!

Oct 19, 2010 at 11:03 AM

This is getting funny (in an entirely not-funny way, that is) - I can reproduce the "Code 3" error with this line:

//AffineThreadPool.QueueUserWorkItem(donothing);
int i = AffineThreadPool.Processors;

Instead of queuing *any* tasks (.NET executes the static constructor of the AffineThreadPool when the class is accessed the first time, so without that line, the AffineThreadPool class would be just dead code)

I also commented out Thread.Start() in the AffineThreadPool's constructor (so no threads are running).

Oct 19, 2010 at 11:27 AM

I can reproduce the "Code 3" error with the following snippet:

public static class AffineThreadPool {

  /// <summary>Number of CPU cores available on the system</summary>
  public static readonly int Processors = 4;

  /// <summary>Initializes the thread pool</summary>
  static AffineThreadPool() {

    // Create all of the worker threads
    for (int index = 0; index < Processors; index++) {

      // Create a new thread and add it to the list of threads.
      Thread newThread = new Thread(new ThreadStart(ProcessQueuedItems));

      // Notice there's no Thread.Start() here.

    }

  }

  /// <summary>A thread worker function that processes items from the work queue</summary>
  private static void ProcessQueuedItems() {}

}

I'm not one to easily put the blame on others, but I'm beginning to think that it's not entirely out of the question that this bug might be somewhere else.

I'll try to get some feedback in the XNA forums. And unless those 9 lines of code above contain a bug, I'll file a bug on Microsoft Connect and see if I can find a workaround for my AffineThreadPool until the bug is solved.

Oct 19, 2010 at 11:43 AM

FYI, I didn't overlook that the crash went away when you added a delay in your Update() method.

It seems to only happen if the static constructor of the AffineThreadPool runs during the first time Update() is called.

 

Could you try if the crash goes away when you put

int i = AffineThreadPool.Processors

into your game's Initialize() method, thereby executing the static constructor earlier?

 

Also, I have entered a bug in CodePlex' issue tracker with my minimal reproduction case attached. Can you confirm that it reproduces the bug for you as well?

http://nuclexframework.codeplex.com/workitem/5314

 

Thanks!