-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
160 additions
and
46 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 |
---|---|---|
@@ -1,52 +1,50 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using ThreadingTest; | ||
|
||
namespace ThreadingTest | ||
{ | ||
internal sealed class Program | ||
{ | ||
private static async Task Main(string[] args) | ||
{ | ||
//TaskDelayTest.Test(); | ||
// TaskDelayTest.Test(); | ||
|
||
// TaskDelayTest.Exception_Test(); | ||
// TaskDelayTest.Exception_Catch_Test(); | ||
|
||
//TaskDelayTest.Exception_Test(); | ||
//TaskDelayTest.Exception_Catch_Test(); | ||
// ReaderWriterLockTest.ReaderWriterLock_Test(); | ||
// ReaderWriterLockTest.UpgradeToWriterLock_Test(); | ||
// ReaderWriterLockTest.ReleaseLock_Test(); | ||
|
||
//ReaderWriterLockTest.ReaderWriterLock_Test(); | ||
//ReaderWriterLockTest.UpgradeToWriterLock_Test(); | ||
//ReaderWriterLockTest.ReleaseLock_Test(); | ||
// ReaderWriterLockSlimTest.TryEnterReadLock_Test(); | ||
// ReaderWriterLockSlimTest.EnterUpgradeableReadLock_WhenHasRead_Test(); | ||
// ReaderWriterLockSlimTest.EnterUpgradeableReadLock_WhenHasWrite_Test(); | ||
// ReaderWriterLockSlimTest.ExitUpgradeableReadLock_Test(); | ||
// ReaderWriterLockSlimTest.EnterUpgradeableReadLock_OnlyOne_Test(); | ||
// ReaderWriterLockSlimTest.Upgradeable_ToRead_Test(); | ||
|
||
//ReaderWriterLockSlimTest.TryEnterReadLock_Test(); | ||
//ReaderWriterLockSlimTest.EnterUpgradeableReadLock_WhenHasRead_Test(); | ||
//ReaderWriterLockSlimTest.EnterUpgradeableReadLock_WhenHasWrite_Test(); | ||
//ReaderWriterLockSlimTest.ExitUpgradeableReadLock_Test(); | ||
//ReaderWriterLockSlimTest.EnterUpgradeableReadLock_OnlyOne_Test(); | ||
//ReaderWriterLockSlimTest.Upgradeable_ToRead_Test(); | ||
// ChannelTest.Reader_Test(); | ||
|
||
//ChannelTest.Reader_Test(); | ||
// CancellationTokenTest.Cancel_Test(); | ||
|
||
//CancellationTokenTest.Cancel_Test(); | ||
// InterruptTest.Sleeping_Interrupt_Test(); | ||
|
||
//InterruptTest.Sleeping_Interrupt_Test(); | ||
// ThreadPoolTest.Enqueue_Test(); | ||
// ThreadPoolTest.Starvation_WaitThread_Test(); | ||
// ThreadPoolTest.Starvation_SetMinThreads_Test(); | ||
|
||
//ThreadPoolTest.Enqueue_Test(); | ||
//ThreadPoolTest.Starvation_WaitThread_Test(); | ||
//ThreadPoolTest.Starvation_SetMinThreads_Test(); | ||
// ThreadPoolTest.Starvation_UseGlobalQueue_Test1(); | ||
// ThreadPoolTest.Starvation_UseThreadLocalQueue_Test2(); | ||
// ThreadPoolTest.Starvation_UseGlobalQueue_Test3(); | ||
|
||
//ThreadPoolTest.Starvation_UseGlobalQueue_Test1(); | ||
//ThreadPoolTest.Starvation_UseThreadLocalQueue_Test2(); | ||
//ThreadPoolTest.Starvation_UseGlobalQueue_Test3(); | ||
// ThreadPoolTest.WithoutDelay_UseGlobalQueue_Test1(); | ||
|
||
ThreadPoolTest.WithoutDelay_UseGlobalQueue_Test1(); | ||
// ThreadPoolTest.SetMinThreads_UseGlobalQueue_Test1(); | ||
|
||
//ThreadPoolTest.SetMinThreads_UseGlobalQueue_Test1(); | ||
// TaskRunTest.RunWithThrow_NoWait(CancellationToken.None); | ||
// TaskRunTest.RunWithThrow_NoWait_Continue(CancellationToken.None); | ||
// await TaskRunTest.RunWithThrow_Async(CancellationToken.None); | ||
// await TaskRunTest.RunWithThrow_Async_ContinueAsync(CancellationToken.None); | ||
TaskRunTest.CallAsync_NoWait(CancellationToken.None); | ||
|
||
while (true) | ||
{ | ||
await Task.Delay(1000); | ||
Console.WriteLine($"ThreadCount: {ThreadPool.ThreadCount}"); | ||
} | ||
} | ||
} | ||
while (true) | ||
{ | ||
await Task.Delay(1000); | ||
Console.WriteLine($"ThreadCount: {ThreadPool.ThreadCount}"); | ||
} |
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,100 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace ThreadingTest; | ||
|
||
internal static class TaskRunTest | ||
{ | ||
|
||
#region Constants & Statics | ||
|
||
public static void CallAsync_NoWait(CancellationToken cancellationToken = default) | ||
{ | ||
// don't crash! | ||
|
||
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed | ||
_ = RunWithThrow_Async(cancellationToken); | ||
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed | ||
} | ||
|
||
public static async Task RunWithThrow_Async(CancellationToken cancellationToken = default) | ||
{ | ||
// program crash! | ||
// Unhandled exception. | ||
|
||
var t = Task.Run( | ||
() => | ||
{ | ||
Console.WriteLine("RunWithThrow_Async"); | ||
throw new NotSupportedException("throw internal Task.Run"); | ||
}, | ||
cancellationToken); | ||
|
||
await t; | ||
} | ||
|
||
public static async Task RunWithThrow_Async_ContinueAsync(CancellationToken cancellationToken = default) | ||
{ | ||
// don't crash! | ||
|
||
var t = Task | ||
.Run( | ||
() => | ||
{ | ||
Console.WriteLine("RunWithThrow_Async"); | ||
throw new NotSupportedException("throw internal Task.Run"); | ||
}, | ||
cancellationToken) | ||
.ContinueWith( | ||
(t) => | ||
{ | ||
if (t.IsFaulted) | ||
{ | ||
Console.WriteLine(t.Exception.Message); | ||
} | ||
}, | ||
cancellationToken); | ||
|
||
await t; | ||
} | ||
|
||
public static void RunWithThrow_NoWait(CancellationToken cancellationToken = default) | ||
{ | ||
// don't crash! | ||
|
||
_ = Task.Run( | ||
() => | ||
{ | ||
Console.WriteLine("RunWithThrow_NoWait"); | ||
throw new NotSupportedException("throw internal Task.Run"); | ||
}, | ||
cancellationToken); | ||
} | ||
|
||
public static void RunWithThrow_NoWait_Continue(CancellationToken cancellationToken = default) | ||
{ | ||
// don't crash! | ||
|
||
_ = Task | ||
.Run( | ||
() => | ||
{ | ||
Console.WriteLine("RunWithThrow_NoWait"); | ||
throw new NotSupportedException("throw internal Task.Run"); | ||
}, | ||
cancellationToken) | ||
.ContinueWith( | ||
(t) => | ||
{ | ||
if (t.IsFaulted) | ||
{ | ||
Console.WriteLine(t.Exception.Message); | ||
} | ||
}, | ||
cancellationToken); | ||
} | ||
|
||
#endregion | ||
|
||
} |