-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[w32handle] Only own first handle if doing WaitHandle.WaitAny (#5625)
This is the behaviour on .NET, even if it goes against the documentation at https://msdn.microsoft.com/en-us/library/tdykks7z(v=vs.110).aspx#Anchor_2 Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=59281
- Loading branch information
1 parent
7ba4e9e
commit 0dd35e9
Showing
3 changed files
with
60 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System; | ||
using System.Threading; | ||
|
||
class Driver | ||
{ | ||
|
||
static readonly Mutex[] mutexes = new Mutex[2]; | ||
|
||
public static void Main(string[] args) | ||
{ | ||
for (int i = 0; i < mutexes.Length; i++) { | ||
mutexes [i] = new Mutex(); | ||
} | ||
|
||
Thread thread1 = new Thread(() => { | ||
for (int i = 0; i < 1; i++) { | ||
int idx = -1; | ||
try { | ||
idx = WaitHandle.WaitAny (mutexes); | ||
Console.WriteLine($"Thread 1 iter: {i} with mutex: {idx}"); | ||
} finally { | ||
if (idx != -1) | ||
mutexes [idx].ReleaseMutex(); | ||
} | ||
} | ||
Console.WriteLine("Thread 1 ended"); | ||
}); | ||
|
||
thread1.Start(); | ||
thread1.Join(); | ||
|
||
Thread thread2 = new Thread(() => { | ||
for (int i = 0; i < 1000; i++) { | ||
int idx = -1; | ||
try { | ||
idx = WaitHandle.WaitAny (mutexes); | ||
Console.WriteLine($"Thread 2 iter: {i} with mutex: {idx}"); | ||
} finally { | ||
if (idx != -1) | ||
mutexes [idx].ReleaseMutex(); | ||
} | ||
} | ||
Console.WriteLine("Thread 2 ended"); | ||
}); | ||
|
||
thread2.Start(); | ||
thread2.Join(); | ||
} | ||
} |