Thread safety

Topics: Metadata Model, PDB Reader, PDB Writer, PE reader, PE Writer, Source Model
Apr 21, 2010 at 9:56 AM
Edited Apr 21, 2010 at 11:14 AM

Hi,

I would like to know what parts/components of the CCI Metadata are thread-safe?
I.e. are the PeReader, PeWriter, PdbReader, PdbWriter, DefaultHost, InternFactory, NameTable thread-safe?

Regards,
artr

Coordinator
May 22, 2010 at 3:29 AM

PeReader is thread safe. PdbReader is not, although I'd like it to be. PeWriter and PdbWriter are safe in as much as they do all their work in a single method call. However, they'll do bad things if other thread simultaneously try to write to the target stream.

DefaultHost was meant to be thread safe, but I see that an unguarded mutator have crept in (AddLibPath). InternFactory and NameTable are thread-safe.

May 22, 2010 at 6:34 AM

It seems like I have found a thread-safety problem in PeReader.

Here is the stack trace you can get to it:
- when calling Microsoft.Cci.MetadataReader.ObjectModelImplementation.TypeBase.BaseClasses
- it will use Microsoft.Cci.MetadataReader.ObjectModelImplementation.TypeBase.BaseTypeReference
- which will call Microsoft.Cci.MetadataReader.PEFileToObjectModel.GetBaseTypeForType
- then Microsoft.Cci.MetadataReader.PEFileToObjectModel.GetTypeReferenceForToken
- then the other overload of Microsoft.Cci.MetadataReader.PEFileToObjectModel.GetTypeReferenceForToken
- which will call Microsoft.Cci.MetadataReader.PEFileToObjectModel.GetTypeSpecReferenceAtRow
- which uses ModuleTypeSpecHashtable (it is of DoubleHashtable type) without acquiring the global lock first.

And it seems like DoubleHashtable is not thread-safe.

Regards, artr