[runtime] Move more thread attach code to mono-threads from io-layer.
Fix src and dest indexes in DispatcherOperation ctor

The source and the destination indexes are confused. The source index, which
is the second parameter, should be 0 and the destination index, which is the
fourth parameter, should be 1.
Dispatcher.PushFrame: clean references before return

The dispatcher did not clean references before returning, therefore
the second call to Dispatcher.Run() failed.
[runtime] Simplify the io-layer threading code a bit more.
Dispatcher: Run() can be used more than once

When Run() was invoked a second time, main_execution_frame had the Continue
flag set to false. So it did not work correctly.
Dispatcher should stop if Continue is false

If the dispatcher encounters that frame.Continue is false, it should return
immediately and do not try to execute anything. The unit test may be seen as
rather artificial, but the problem may happen in more realistic situations
when frames are unwound.
InvalidOperationException in Dispatcher.RunFrame

When a Dispatcher exits due to 'frame.Continue' being false, it does not
clear queue_bits. As result, the next run of the Dispatcher could try to
dequeue a non-existing dispatcher operation.
Dispatcher should process a higher-priority task

When a higher-priority tasked appeared in the dispatcher queue, the
dispatcher stopped processing of the current queue but moved to a low
priority queue instead of processing the most high priority queue.
Merge pull request #886 from dmpot/master

[WindowsBase]: 6 fixes to Dispatcher
[corlib] Throw correct exception when array::copy elements don't match
[corlib] Clean up array binary search argument checks
[corlib] Allow to use custom comparer when sorting null values.
[runtime] Applied patch from Frank Fuchs <fk.fuchs@googlemail.com>. Fix the windows build.
[runtime] Applied patch from Frank Fuchs <fk.fuchs@googlemail.com>. Add win64 support to mono_threads_core_get_stack_bounds ().
[corlib] Add overflow checks to functions that alloc memory and uses raw pointers.
[corlib] The hashcode of an empty struct must be constant. Fixes #17577
Merge branch 'master'