-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shouldn't TypeDictionary
be thread-safe?
#12
Comments
It's very rough and limited. And it assumes eiriktsarpalis#12 is addressed.
It's very rough and limited. And it assumes eiriktsarpalis#12 is addressed.
It isn't intended to be thread-safe, no. The only differentiator for this type over a regular
That's correct. There's no real solution I know of other than taking a lock on the dictionary while a particular type graph is being built. That's probably acceptable given it's a one-time cost per type (System.Text.Json also does it this way). Another alternative is keeping a global |
FWIW the F# variant of the library defines a thread-safe Maybe it's useful to port this pattern to C# as well. |
I suppose making that collection thread-safe isn't a good solution because if multiple graphs were being constructed concurrently, there's no guarantee that one type isn't requested and activated before it's "ready". |
* Add MsgPackSerializer sample It's very rough and limited. And it assumes #12 is addressed. * Add msgpack benchmarks * Perf improvements * More perf improvements * Use list instead of dictionary for writing properties * Remove unnecessary code * Fix thread-safety * Generate `IMessagePackFormatter<T>` implementations * Remove extra level of indirection * Fix failing unit tests * Handle more primitive types and defer missing construction complaint till deserialization * Fix DelayedFormatter pattern * Store primitive formatters in a static dictionary * Add support for enums * Got non-default constructors working * Remove workaround that is no longer required * Serialize enum as underlying type rather than string * Add msgpack Theory * Replace msgpack sample with a reference --------- Co-authored-by: Eirik Tsarpalis <[email protected]>
I know it's just in the Samples area, but as sample tend to be copied for production code, shouldn't
TypeDictionary
be thread-safe?It looks like maybe it doesn't need to be for present purposes because the existing uses create a new instance of
Builder
classes soTypeDictionary
is never shared across threads. But that means multiple type graphs that overlap will produce redundant serializers, if I understand correctly.The text was updated successfully, but these errors were encountered: