Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is ArrayPool<T>.Rent(Int32) Method thread-safe?

I just found out about ArrayPool existence, but it's documentation is somewhat lacking.

I'd like to know if Rent(.) and Return(.) are thread-safe.

Edit: looks like I didn't notice the "Thread Safety" part of documentation; but reading some of the comments and answers I was relieved I wasn't the only one that didn't.

like image 523
Trauer Avatar asked Nov 13 '18 03:11

Trauer


People also ask

Is ArrayPool thread-safe?

Thread SafetyThis class is thread-safe. All members may be used by multiple threads concurrently.

Is .NET core thread-safe?

In common application models, only one thread at a time executes user code, which minimizes the need for thread safety. For this reason, the . NET class libraries are not thread safe by default.

What is ArrayPool?

ArrayPool<T> vs. Memory pools are used to reuse existing memory blocks; you can use them to allocate memory blocks dynamically. Array pools manage a pool of arrays and rent them when asked for.

What is thread-safe in C# with example?

Thread safety is the technique which manipulates shared data structure in a manner that guarantees the safe execution of a piece of code by the multiple threads at the same time. A code is called thread-safe. If it is run concurrently without break function.


1 Answers

it's documentation is somewhat lacking.

You can read about thread safety under Thread Safety:

Thread Safety

This class is thread-safe. All members may be used by multiple threads concurrently.

like image 79
ta.speot.is Avatar answered Sep 20 '22 15:09

ta.speot.is