Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / tests / thread-native-exit.cs
1
2 using System;
3 using System.Runtime.InteropServices;
4 using System.Threading;
5
6 class Driver
7 {
8         [DllImport ("libc")]
9         extern static void pthread_exit (IntPtr value);
10
11         [DllImport ("kernel32")]
12         extern static void ExitThread (IntPtr value);
13
14         static Thread GetThread1 ()
15         {
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                 });
23         }
24
25         static Thread GetThread2 ()
26         {
27                 return new Thread (() => {
28                         /* Exit without returning from the ThreadStart delegate */
29                         Thread.CurrentThread.Abort ();
30                 });
31         }
32
33         static Thread GetThread3 ()
34         {
35                 return new Thread (() => {
36                         /* Exit by returning from the ThreadStart delegate */
37                         return;
38                 });
39         }
40
41         static Thread[] CreateThreads ()
42         {
43                 return new Thread [] {
44                         GetThread1 (),
45                         GetThread2 (),
46                         GetThread3 (),
47                 };
48         }
49
50         public static void Main ()
51         {
52                 Thread[] threads;
53
54                 {
55                         threads = CreateThreads ();
56
57                         for (int i = 0; i < threads.Length; ++i)
58                                 threads [i].Start ();
59
60                         for (int i = 0; i < threads.Length; ++i)
61                                 threads [i].Join ();
62                 }
63
64                 {
65                         threads = CreateThreads ();
66
67                         for (int i = 0; i < threads.Length; ++i)
68                                 threads [i].Start ();
69                 }
70         }
71 }