Created
November 12, 2017 13:28
-
-
Save patricksuo/af375b0eacbe6df5a5c49c92cda6c7be to your computer and use it in GitHub Desktop.
This file contains hidden or 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
using System; | |
using System.Threading; | |
using System.Threading.Tasks; | |
namespace ConsoleApp1 | |
{ | |
class Program | |
{ | |
static SemaphoreSlim mSema1 = new SemaphoreSlim(1); | |
static SemaphoreSlim mSema2 = new SemaphoreSlim(0); | |
static SemaphoreSlim mSema3 = new SemaphoreSlim(0); | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Hello World!"); | |
var t1 = Task.Run(BlockForTaskDelay); | |
var t2 = Task.Run(BlockForSystemCall); | |
var t3 = Task.Run(BlockForDeadlock); | |
var t4 = Task.Run(RunningDummyWorkload); | |
Task.WhenAll(t1, t2, t3).Wait(); | |
} | |
static async Task BlockForTaskDelay() | |
{ | |
await Task.Delay(-1); | |
} | |
static async Task BlockForSystemCall() | |
{ | |
await Task.Yield(); | |
Thread.Sleep(-1); | |
} | |
static async Task BlockForDeadlock() | |
{ | |
await mSema1.WaitAsync(); | |
await mSema2.WaitAsync(); | |
await mSema3.WaitAsync(); | |
} | |
static async Task RunningDummyWorkload() | |
{ | |
await Task.Yield(); | |
while (true) | |
{ | |
Thread.Yield(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment