Skip to content

Instantly share code, notes, and snippets.

@hkucuk
Last active February 7, 2022 19:51
Show Gist options
  • Select an option

  • Save hkucuk/885fe35a999dde8c2380f358f67db386 to your computer and use it in GitHub Desktop.

Select an option

Save hkucuk/885fe35a999dde8c2380f358f67db386 to your computer and use it in GitHub Desktop.

Revisions

  1. hkucuk revised this gist Feb 7, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion simple_thread_sync_2.cs
    Original file line number Diff line number Diff line change
    @@ -29,7 +29,7 @@
    Thread.Sleep(3000);
    Console.WriteLine("Main thread 1. sinyali gönderdi");
    ms.Set();
    ms.Reset();
    ms.Reset(); //Nesne unsignaled duruma getirilir
    Thread.Sleep(3000);
    Console.WriteLine("Main thread 2. sinyali gönderdi");
    ms.Set();
  2. hkucuk created this gist Feb 7, 2022.
    37 changes: 37 additions & 0 deletions simple_thread_sync_2.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    var ms = new ManualResetEvent(false);

    var t1 = new Thread(new ParameterizedThreadStart(x =>
    {
    Console.WriteLine("1 numaralı thread 1. sinyali sinyal bekliyor");
    ms.WaitOne();
    Console.WriteLine("1 numaralı thread 1. sinyali aldı");
    Console.WriteLine("1 numaralı thread 2. sinyali sinyal bekliyor");
    ms.WaitOne();
    Console.WriteLine("1 numaralı thread 2. sinyali aldı");
    }));

    t1.Start();


    var t2 = new Thread(new ParameterizedThreadStart(x =>
    {
    Console.WriteLine("2 numaralı thread 1. sinyali sinyal bekliyor");
    ms.WaitOne();
    Console.WriteLine("2 numaralı thread 1. sinyali aldı");
    Console.WriteLine("2 numaralı thread 2. sinyali sinyal bekliyor");
    ms.WaitOne();
    Console.WriteLine("2 numaralı thread 2. sinyali aldı");

    }));

    t2.Start();

    Thread.Sleep(3000);
    Console.WriteLine("Main thread 1. sinyali gönderdi");
    ms.Set();
    ms.Reset();
    Thread.Sleep(3000);
    Console.WriteLine("Main thread 2. sinyali gönderdi");
    ms.Set();

    Console.WriteLine("Main thread bitti");