Last active
December 27, 2020 11:59
-
-
Save ierhalim/8005c3b3a9f2d88299cf7d511449ff6e to your computer and use it in GitHub Desktop.
Y2O4 Paralel programlama
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 DataSharing | |
| { | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| var readerWriterLock = new ReaderWriterLockSlim(); | |
| int value = 10; | |
| Console.WriteLine("Press a key to increase the number"); | |
| var task = Task.Run(() => | |
| { | |
| while (true) | |
| { | |
| try | |
| { | |
| readerWriterLock.EnterReadLock(); | |
| Console.WriteLine(value); | |
| Thread.Sleep(5000); | |
| } | |
| finally | |
| { | |
| readerWriterLock.ExitReadLock(); | |
| } | |
| } | |
| }); | |
| while (true) | |
| { | |
| Console.ReadKey(); | |
| readerWriterLock.EnterWriteLock(); | |
| value++; | |
| readerWriterLock.ExitWriteLock(); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment