[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


https://bugzilla.novell.com/show_bug.cgi?id=549807

https://bugzilla.novell.com/show_bug.cgi?id=549807#c2


--- 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.OpenExisting("done");

            EventWaitHandle[] handles = new EventWaitHandle[] {
                doneEvent
            };

            int index;

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

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

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

            Console.WriteLine("Thread exited loop.");
        }
        #endregion

       
///////////////////////////////////////////////////////////////////////////

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

    ///////////////////////////////////////////////////////////////////////////

    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);

        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
        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);

            thread.Start();

            Thread.Sleep(2000);

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

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

            Thread.Sleep(2000);

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

            Console.ReadKey();
        }
    }
}

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