[Mono-dev] Issues with Thread.CurrentThread on 4.2

Martin Potter Martin.Potter at faithlife.com
Thu Nov 12 17:42:09 UTC 2015


We have some code which works on Microsoft's runtime and used to work on Mono 3.12, but now fails on Mono 4.2. Simplified code to reproduce the issue is as follows:

public class WorkStateThread
{
public void Start()
{
m_thread = new Thread(ThreadProc);
m_thread.Start(Thread.CurrentThread);
m_thread.Join();
}

private void ThreadProc (object objData)
{
if (m_thread != Thread.CurrentThread)
throw new InvalidOperationException ("m_thread != Thread.CurrentThread");
}

Thread m_thread;
}

class MainClass
{
public static void Main (string[] args)
{
WorkStateThread ws = new WorkStateThread ();
ws.Start ();
Console.WriteLine ("Done");
}
}

[TestFixture]
public class Test
{
[Test]
public void TestCase ()
{
WorkStateThread ws = new WorkStateThread ();
ws.Start ();
}
}

This code runs as expected when run from the command line, but if run as part of a unit test using NUnit, the InvalidOperationException is thrown.

- Martin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-devel-list/attachments/20151112/749945d6/attachment.html>


More information about the Mono-devel-list mailing list