[Mono-bugs] [Bug 549807] WaitHandle.WaitAny returns WAIT_IO_COMPLETION (an impossible return value for .NET)

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Tue Aug 31 01:00:20 EDT 2010



--- Comment #2 from Joe Mistachkin <joe at mistachkin.com> 2010-08-31 05:00:18 UTC ---
Here is your isolated test case:

1. Compile the following code with gmcs or .NET.
2. Run the code under .NET (no exception occurs).
3. Run the code under Mono (array index out of range exception occurs).
4. Pay special attention to the "WaitAny returned XXX" console output.

using System;
using System.Runtime.InteropServices;
using System.Threading;

namespace ConsoleApplication1
    internal static class bug549807
        #region Thread Procedure
        internal static void ThreadStart()
            Program.threadId = unchecked((uint)AppDomain.GetCurrentThreadId());

            EventWaitHandle doneEvent =

            EventWaitHandle[] handles = new EventWaitHandle[] {

            int index;

            Console.WriteLine("Thread entering loop.");

            while ((index = ManualResetEvent.WaitAny(handles, 4000, false)) >
                Console.WriteLine("WaitAny returned {0}", index);

                if (index != EventWaitHandle.WaitTimeout)
                    handles[index].Reset(); /* NOTE: Exception here on Mono. */

            Console.WriteLine("Thread exited loop.");


        #region Asynchronous Event Callback Procedure
        internal static void EventCallback(IntPtr data)
            Console.WriteLine("this is the event callback");


    internal static class Program
        internal static uint threadId = 0;

        internal const uint THREAD_SET_CONTEXT = 0x10; /* NOTE: For
QueueUserAPC. */

        [DllImport("kernel32", CallingConvention = CallingConvention.Winapi,
SetLastError = true)]
        internal static extern IntPtr OpenThread(uint desiredAccess, bool
inheritHandle, uint threadId);

        [DllImport("kernel32", CallingConvention = CallingConvention.Winapi)]
        internal static extern uint QueueUserAPC(ApcCallback proc, IntPtr
thread, IntPtr data);

        public delegate void ApcCallback(IntPtr data);

        private static void Main(string[] args)
            EventWaitHandle doneEvent = new EventWaitHandle(
                false, EventResetMode.ManualReset, "done");

            Thread thread = new Thread(bug549807.ThreadStart);



            IntPtr threadPtr = OpenThread(THREAD_SET_CONTEXT, false, threadId);

            if (QueueUserAPC(bug549807.EventCallback, threadPtr, IntPtr.Zero)
!= 0)
                Console.WriteLine("APC queued.");


            doneEvent.Set(); /* kill thread. */


Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.

More information about the mono-bugs mailing list