I'm using IStorage's Compound File Implementation from C# (StgCreateDocfile).
我正在使用来自C#(StgCreateDocfile)的IStorage的复合文件实现。
Is it safe to access one IStorage / IStream instance from multiple threads, provided I synchronized the reads and writes myself? Or are there any COM issues that might be problematic here?
如果我自己同步读写,那么从多个线程访问一个IStorage / IStream实例是否安全?或者是否存在可能存在问题的COM问题?
For example, can I safely call EnumElements to get all streams in the storage, while at the same time (and from a different thread) creating and writing a new stream?
例如,我可以安全地调用EnumElements来获取存储中的所有流,同时(以及从不同的线程)创建和编写新流吗?
I have already written a stress test for my implementation, and it showed no problems, but I need to be 100% sure. I haven't found this information in the MSDN docs.
我已经为我的实现编写了压力测试,它没有显示任何问题,但我需要100%肯定。我没有在MSDN文档中找到此信息。
1 个解决方案
#1
1
Tuff one. There's a snippet about it in the documentation for the ILockBytes interface. It says that the default implementations of IStorage and IStream implement IMarshal. Which would make them thread-safe, provided you follow COM threading rules. That's easy to forget when the interface pointers are in-proc. You'd have to use something like CoMarshalInterThreadInterfaceInStream() or IGlobalInterfaceTable. You'll get away with not marshaling by locking yourself.
凝灰岩一个。在ILockBytes接口的文档中有一个关于它的片段。它说IStorage和IStream的默认实现实现了IMarshal。如果您遵循COM线程规则,这将使它们成为线程安全的。当接口指针在进程中时,很容易忘记。你必须使用像CoMarshalInterThreadInterfaceInStream()或IGlobalInterfaceTable这样的东西。你可以通过锁定自己来避免编组。
#1
1
Tuff one. There's a snippet about it in the documentation for the ILockBytes interface. It says that the default implementations of IStorage and IStream implement IMarshal. Which would make them thread-safe, provided you follow COM threading rules. That's easy to forget when the interface pointers are in-proc. You'd have to use something like CoMarshalInterThreadInterfaceInStream() or IGlobalInterfaceTable. You'll get away with not marshaling by locking yourself.
凝灰岩一个。在ILockBytes接口的文档中有一个关于它的片段。它说IStorage和IStream的默认实现实现了IMarshal。如果您遵循COM线程规则,这将使它们成为线程安全的。当接口指针在进程中时,很容易忘记。你必须使用像CoMarshalInterThreadInterfaceInStream()或IGlobalInterfaceTable这样的东西。你可以通过锁定自己来避免编组。