[System] Tweak socket test
[mono-project.git] / mono / tests / thread-native-exit.cs
blobe112be0fa16e46960bfafae3f5572c7bbd08bfb0
2 using System;
3 using System.Runtime.InteropServices;
4 using System.Threading;
6 class Driver
8 [DllImport ("libc")]
9 extern static void pthread_exit (IntPtr value);
11 [DllImport ("kernel32")]
12 extern static void ExitThread (IntPtr value);
14 static Thread GetThread1 ()
16 return new Thread (() => {
17 /* Exit bypassing completely the runtime */
18 if (Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX)
19 pthread_exit (IntPtr.Zero);
20 else
21 ExitThread (IntPtr.Zero);
22 });
25 static Thread GetThread2 ()
27 return new Thread (() => {
28 /* Exit without returning from the ThreadStart delegate */
29 Thread.CurrentThread.Abort ();
30 });
33 static Thread GetThread3 ()
35 return new Thread (() => {
36 /* Exit by returning from the ThreadStart delegate */
37 return;
38 });
41 static Thread[] CreateThreads ()
43 return new Thread [] {
44 GetThread1 (),
45 GetThread2 (),
46 GetThread3 (),
50 public static void Main ()
52 Thread[] threads;
55 threads = CreateThreads ();
57 for (int i = 0; i < threads.Length; ++i)
58 threads [i].Start ();
60 for (int i = 0; i < threads.Length; ++i)
61 threads [i].Join ();
65 threads = CreateThreads ();
67 for (int i = 0; i < threads.Length; ++i)
68 threads [i].Start ();