From the course: Threading in C#

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Shared resources

Shared resources - C# Tutorial

From the course: Threading in C#

Start my 1-month free trial

Shared resources

- [Instructor] So how does multithreading work? The operating system has a thread scheduler which manages multithreading for us. The .NET CLR delegates this task to the operating system and works directly with the thread scheduler what happens with shared resources inside that process or that application. The CLR assigns each thread its own local memory stack. This way the local variables are kept completely separated. So if you have a for loop that has zero to 10 count, and then you print all the values from zero to 10, it really doesn't matter how many different threads call that for loop. For every single thread, there will be a local memory stack where that particular variable will have the values from zero all the way to 10, and it will not interfere with other threads. Now how do you take values that actually could be shared between multiple threads? So if you used static variable, and you want to share that value between multiple threads, that's definitely possible. It's the…

Contents