锁定正在减慢ThreadPool&的性能.与任务并行循环 [英] Lock is slowing down the performance of ThreadPool & Parallel For Loop with Tasks

查看:52
本文介绍了锁定正在减慢ThreadPool&的性能.与任务并行循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我已经开发了一个使用线程池和应用程序的应用程序.并行循环
带锁.
但是,当我使用lock时,它会减慢Thread Pool&的进程.并行循环.



请帮帮我.

在此先感谢



I have developed an application in which i am using Thread Pool & Parallel for loop
with lock.
But when i use lock , it slower downs the process of Thread Pool & Parrallel for loop.



Please help me.

Thanks in advance

推荐答案

而没有看到代码并不是预期的那样.如果使用锁,则在释放锁之前,禁止同时进行的操作获取相同的锁.因此,您正在排队寻求锁定.
Without seeing the code isn''t that what''s expected to happen. If you use lock, you prevent simultaneous operations from acquiring the same lock until the lock is released. So you''re queueing for the lock.


尽管使用C#4 [假定标记!],但我认为您不必担心锁定对象/线程池.您可以使用 Parallel.For [
While using C#4 [Assumed from the tag!] , I don''t think that you have to worry about locking the objects / Threadpool. You can make use of Parallel.For[^] method.

For more details search for PLINQ and TPL


这篇关于锁定正在减慢ThreadPool&的性能.与任务并行循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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