Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CLR: How is generation 0 shared by all threads?

Tags:

.net

clr

I cannot imagine there is a single lock that all threads must acquire in order to allocate memory. So are there multiple Gen 0 heaps? Is there one that is partitioned amongst the threads?

like image 421
Jonathan Allen Avatar asked Jan 20 '11 09:01

Jonathan Allen


1 Answers

From this article: Garbage Collection Part 2: Automatic Memory Management in the Microsoft .NET Framework by Jeffrey Richter

Synchronization-free Allocations On a multiprocessor system, generation 0 of the managed heap is split into multiple memory arenas using one arena per thread. This allows multiple threads to make allocations simultaneously so that exclusive access to the heap is not required.

Scalable Collections On a multiprocessor system running the server version of the execution engine (MSCorSvr.dll), the managed heap is split into several sections, one per CPU. When a collection is initiated, the collector has one thread per CPU; all threads collect their own sections simultaneously. The workstation version of the execution engine (MSCorWks.dll) doesn't support this feature.

There is a lot other things going on, look for the "Performance for Multithreaded Applications" headline.

like image 182
Lasse Espeholt Avatar answered Nov 07 '22 19:11

Lasse Espeholt