Skip to content

MaartenGDev/multi-threading

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Practice environment

This project has been setup to practice with more advanced c#/.NET topics such as multi-threaded applications. It includes a demo-api and various examples of multi-threading approaches

Topics

Setup

  • Run Demo/Program.cs

Example demonstration

public void ExchangeBook(BookReader otherReader)
{
    Mutex[] locks = new Mutex[] {_lock, otherReader._lock};

    if (WaitHandle.WaitAll(locks))
    {
        var book = otherReader.GetBook();

        if (book != null)
        {
            ReceiveBook(book);
            otherReader.TakeBook(book);  
                
            Console.WriteLine("Reader {0} -> {1} gave book {2}", otherReader.Id, Id, book.Name);
        }
    }

    foreach (var lockedMutex in locks)
    {
        lockedMutex.ReleaseMutex();
    }
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages