Bug 39178 - Thread comparison fails when running under mono-service
Summary: Thread comparison fails when running under mono-service
Status: RESOLVED DUPLICATE of bug 35828
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib (show other bugs)
Version: 4.2.0 (C6)
Hardware: All All
: --- normal
Target Milestone: Untriaged
Assignee: Ludovic Henry
URL:
Depends on:
Blocks:
 
Reported: 2016-02-27 03:56 UTC by Pablo Ruiz García
Modified: 2016-02-29 15:54 UTC (History)
6 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments

Description Pablo Ruiz García 2016-02-27 03:56:09 UTC
Hi,

The following sample code demostrates an issue by which comparison of manually created Thread instance fails to match Thread.CurrentThread, even when this is the actual thread running.

However, this code only fails when started from mono-service.. 

REPO CODE: 

========
using System;
using System.Threading;

class Program
{
        static Thread _thread = new Thread(new ThreadStart(Find));
        static void Main(string[] arguments)
        {
                _thread.Start();
                Thread.Sleep(500);
        }

        private static void Find()
        {
                Console.WriteLine("Current Thread: {0} (ID: {1}, IsThreadPool: {2}, IsBackground: {3}, HashCode: {4})",
                        Thread.CurrentThread.Name, Thread.CurrentThread.ManagedThreadId, Thread.CurrentThread.IsThreadPoolThread,
                        Thread.CurrentThread.IsBackground, Thread.CurrentThread.GetHashCode());
                Console.WriteLine("This Thread: {0} (ID: {1}, IsThreadPool: {2}, IsBackground: {3}, HashCode: {4})",
                        _thread.Name, _thread.ManagedThreadId, _thread.IsThreadPoolThread,
                        _thread.IsBackground, _thread.GetHashCode());
                Console.WriteLine(_thread == Thread.CurrentThread ? "OK!!" : "FAIL!");
        }
}
=======

OUTPUT:

=======
# mono p.exe
Current Thread:  (ID: 3, IsThreadPool: False, IsBackground: False, HashCode: 3)
This Thread:  (ID: 3, IsThreadPool: False, IsBackground: False, HashCode: 3)
OK!!

# mono-service --debug p.exe
Current Thread:  (ID: 4, IsThreadPool: False, IsBackground: False, HashCode: 4)
This Thread:  (ID: 4, IsThreadPool: False, IsBackground: False, HashCode: 4)
FAIL!
=======
Comment 1 Pablo Ruiz García 2016-02-27 04:01:33 UTC
Also, this is failing with mono 4.2.1.124/39edf24.
However, it did work fine when running with mono 4.0.1.
Comment 2 Raman Sidarakin 2016-02-29 07:59:05 UTC
Also threads comparison fails with mono 4.2.1 64-bit.
Comment 3 Ludovic Henry 2016-02-29 15:54:14 UTC
Hi Pablo,

This is a duplicate of https://bugzilla.xamarin.com/show_bug.cgi?id=35828. 

Please try with a newer version: http://download.mono-project.com/archive/4.2.2/macos-10-x86/MonoFramework-MDK-4.2.2.30.macos10.xamarin.x86.pkg . I just tried with this version and cannot reproduce your bug.

Thank you very much,
Ludovic

*** This bug has been marked as a duplicate of bug 35828 ***

Note You need to log in before you can comment on or make changes to this bug.