dotnet / dotnet-api-docs

.NET API reference documentation (.NET 5+, .NET Core, .NET Framework)
https://docs.microsoft.com/dotnet/api/
Other
739 stars 1.57k forks source link

Document thread safety of RandomNumberGenerator #3741

Open jasper-d opened 4 years ago

jasper-d commented 4 years ago

Issue description I cannot find information w.r.t. the thread safety of members of System.Security.Cryptorgraphy.RandomNumberGenerator. Knowing if calls must be synchronized by the caller is important.

RNGCryptoServiceProvider.GetBytes is thread safe according to the documentation.

Target framework

carlossanlop commented 4 years ago

@bartonjs something we could improve in the Cryptography docs?

bartonjs commented 4 years ago

I don't know where or how we'd document it.

Consequences:

Recommended action:

arielhammon commented 17 hours ago

@jasper-d

I don't know where or how we'd document it.

  • RandomNumberGenerator.Fill, RandomNumberGenerator.GetBytes(int) RandomNumberGenerator.GetInt32(*) are all thread safe, because they're statics, and our default thread-safety statement says statics are thread-safe (though we don't seem to produce the default thread safety statement on the docs anymore?)
  • On .NET Core: the instance methods of the instance produced by RandomNumberGenerator.Create() are thread-safe.
  • Otherwise an instance of RandomNumberGenerator may or may not be thread-safe.

I've searched the documentation and source code for information about the thread-safety of static methods of RandomNumberGenerator. You say they are thread safe because they are statics. I can easily write a static method that is not thread safe, so my question is, are they thread safe because .Net authors ensure that ALL static methods are thread safe or are they thread safe for some other reason?

TIA.