Bug 12036 - Environment.Exit broken when WaitHandle.WaitAny is used in a separate thread
Summary: Environment.Exit broken when WaitHandle.WaitAny is used in a separate thread
Status: RESOLVED NOT_REPRODUCIBLE
Alias: None
Product: Runtime
Classification: Mono
Component: io-layer ()
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-04-29 19:14 UTC by Sean Reque
Modified: 2013-05-08 11:59 UTC (History)
4 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 NOT_REPRODUCIBLE

Description Sean Reque 2013-04-29 19:14:43 UTC
The following program hangs indefinitely using mono 2.10 On Linux. On Windows .NET the application terminates as expected.

  public static void Main(string[] args)
  {
    var threadSignal = new ManualResetEvent(false);
    var blockForever = new Semaphore(0, 10);
    var blockForever2 = new ManualResetEvent(false);
    WaitHandle[] waiters = new WaitHandle[] {blockForever, blockForever2 };
    var thread = new Thread(() => 
    {
      threadSignal.Set();
      WaitHandle.WaitAny(waiters);
    });
    thread.Start();
    threadSignal.WaitOne();
    Thread.Sleep(TimeSpan.FromSeconds(1));
    Console.WriteLine("about to quit");
    Environment.Exit(0);
  }
Comment 1 Sean Reque 2013-04-29 19:16:06 UTC
I forgot to paste the "using" statements at the top. Only two are required:

using System;
using System.Threading;
Comment 2 Zoltan Varga 2013-04-30 07:24:21 UTC
This works on osx both with 2.10/master, so it might be linux only.
Comment 3 Sean Reque 2013-04-30 13:18:21 UTC
Some more information.

The hang does not occur when I use the 2.4.3 rpms provided by EPEL for RHEL6. I do get a hang when I use the 2.10.5 rpms provided by MostlyLinux. In addition, I compiled 2.10.0 from source and and I see a hang when using that binary.
Comment 4 Zoltan Varga 2013-05-06 11:10:49 UTC
I can't reproduce this on linux either (debian x64 2.10 branch at f4239234a2af76dc1b1b288c4ef880e1351c7417).
Comment 5 Sean Reque 2013-05-08 11:58:07 UTC
I also can't reproduce it with a mono built using changeset f4239234a2af76dc1b1b288c4ef880e1351c7417. It appears this issue has been fixed sometime since 2.10.5. I apologize for the inconvenience.