[Mono-list] Bug in method System.Threading.ThreadPool.QueueUserWorkItem
Francesco FD. Delfino
fdelfino@napoli.consorzio-cini.it
Sat, 3 Aug 2002 18:55:13 +0200
Hi,
This simple piece of code demostrate that some problems are in this method (or at least that some classes this method uses are not thread safe/need some fixes):
--- CUT HERE ---
using System;
namespace ConsoleApplication2
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
System.Threading.ThreadPool.QueueUserWorkItem
(new System.Threading.WaitCallback(MyFunction));
}
static void MyFunction(object o)
{
Console.Write("hello world!");
}
}
--- END CUT HERE ---
Using **MINT** the output is the following, both on cygwin and linux:
(process:2640): ** WARNING **: unhandled exception System.IndexOutOfRangeException: "Array index is out of range"
#0: 0x00051 stelem.ref in System.Collections.ArrayList::Add ([00C02DC0] )
#1: 0x00075 callvirt in System.Threading.ThreadPool::CheckIfStartThread ()
#2: 0x00001 call in System.Threading.ThreadPool::AddItem ([0022F4E8] )
#3: 0x0001b call in System.Threading.ThreadPool::QueueUserWorkItemInternal ([00C03C60] [00000000] )
#4: 0x00007 callvirt in System.Threading.ThreadPool::QueueUserWorkItem ([00C03C60] [00000000] )
#5: 0x00002 call in System.Threading.ThreadPool::QueueUserWorkItemInternal ([00C03C60] )
#6: 0x00006 callvirt in System.Threading.ThreadPool::QueueUserWorkItem ([00C03C60] )
#7: 0x0000c call in ConsoleApplication2.Class1::Main ([00C06F60] )
Using **MONO** just the first line appears, then the process seems to hang for a while and then the call stack is printed.
Commenting the ArrayList::Add method in the CheckIfStartThread method allows to bypass the problem, but then each QueueUserWorkItem call would create a new thread. Hope this helps.
Regards,
Francesco