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)

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

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED DUPLICATE of bug 35828

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 ***