它是安全的呼吁ICsharp code.SharpZipLib在多线程并行 [英] Is it safe to call ICsharpCode.SharpZipLib in parallel on multiple threads

查看:379
本文介绍了它是安全的呼吁ICsharp code.SharpZipLib在多线程并行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用的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.

这篇关于它是安全的呼吁ICsharp code.SharpZipLib在多线程并行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆