我们正在使用的COM pression的GZipOutputStream类ICsharp code.SharpZipLib库。我们从一个单独的线程做到这一点。
We are currently using for compression the GZipOutputStream class of ICsharpCode.SharpZipLib library. We do it from a single thread.
我要拆我的输入数据流分成块和COM preSS它们并行。 我很担心,虽然,这个库可能有一些静态的内部,将多个线程,因此腐败所产生的数据流被改写。
I want to split my input data stream into chunks and compress them in parallel. I'm worried though that this library may have some statics inside which will be overwritten from multiple threads and therefore corrupt the resulting stream.
任何想法将AP preciated。
Any thoughts will be appreciated.
这是标准的做法,以确保所有静态成员是线程安全的编码类时。所以,我觉得这是非常不可能的,你将有一个问题,因为这个问题。当然,如果你打算使用的一样的 GZipOutputStream
从不同的线程那么这肯定是有问题的,因为该类的实例成员不是线程安全的。
It is standard practice to make sure all static members are thread-safe when coding classes. So I would think it is very unlikely that you would have a problem due to that issue. Of course, if you plan on using the same GZipOutputStream
from different threads then that would definitely be problematic since instance members of that class are not thread-safe.
您也许什么能够做的就是创建一个线程安全的中间人流
类(想Decorator模式),并传递到 GZipOutputStream
。这个自定义流类,称之为 ThreadSafeStream
,自己愿意接受流
实例,并会使用适当的机制来同步访问吧。
What you might be able to do is to create a thread-safe middleman Stream
class (think decorator pattern) and pass that to the GZipOutputStream
. This custom stream class, call it ThreadSafeStream
, would itself accept a Stream
instance and would use the appropriate mechanisms to synchronize access to it.
您将创建一个 GZipOutputStream
实例为每个线程,他们都将共享相同的 ThreadSafeStream
包装实例。我怀疑有可能会是一个很大的瓶颈,在 ThreadSafeStream
方法,但你应该能够获得一些并行来源于此。
You will create one GZipOutputStream
instance for each thread and they will all share the same ThreadSafeStream
wrapper instance. I suspect there will probably be a lot of bottlenecking in the ThreadSafeStream
methods, but you should be able to gain some parallelism from this.