识别 Concurrency Visualizer 中运行 Parallel.ForEach 的线程
我正在使用 VS2010 中的并发可视化工具。这是一个很棒的功能,但我无法识别 Parallel.ForEach 运行的线程。我在这里附上屏幕截图,希望其他人可以提供帮助。另外,我的应用程序似乎是串行运行的吗?请注意主线程和仅一个其他工作线程上的执行。
注意:当我执行此运行时,我设置了 ParallelOptions.MaxDegreeOfParallelism = Environment.ProcessorCount (= 2)。
任何帮助表示赞赏!
I'm playing around with the concurrency visualizer in VS2010. It's a great feature but I am having trouble identifying the threads where my Parallel.ForEach ran. I'm attaching a screenshot here in the hopes someone else can help. Also, does it appear that my application is running serially? Note the execution on the main thread and only one other worker thread.
Note: When I did this run I set the ParallelOptions.MaxDegreeOfParallelism = Environment.ProcessorCount (= 2).
Any help appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您的应用程序正在使用主线程(它可以在主线程上内联工作)并在此列表底部附近的三个 CLR 工作线程之间切换。 ForEach 的不同部分在不同线程上进行调度是正常的。
单击绿色之一(这些线程之一中的执行块)来检查类堆栈并查看它是否真正在您的 ForEach 上运行。 看到类似的内容
您应该在列表顶部附近
。您还会看到一个灰色的场景标记栏出现在视图的顶部和底部,标记为“Parallel.ForEach”,这对于查看您的应用程序实际上在您感兴趣的代码中的位置非常有用。
图像相当小,因此很难尽管有相当数量的黄色表明您的线程被抢占(被其他工作中断),但要告诉更多信息。这可能是由于您在循环内所做的事情和/或应用程序中发生的其他事情所致。
您可以在此处找到有关将分析器与并行应用程序一起使用的更多信息:
http://msdn .microsoft.com/en-us/library/ff963545.aspx
It looks like you application is using the main thread (it can inline work on the main thread) and switching between the three CLR worker threads near the bottom of this list. It's normal for different parts of the ForEach to be scheduler on different threads.
Click on one of the green (Execution blocks in one of these threads) to examine the class stack and see if it's really working on your ForEach. You should see something like:
near the top of the list.
You'll also see a grey scenario marker bar appear top and bottom of the view labelled "Parallel.ForEach" this is useful for seeing where your application was actually inside the code you're interested in.
The image is rather small so it's hard to tell more although there's a reasonable amount of yellow suggesting your threads are getting preempted (interupted by other work). This may be due to what you're doing inside the loop and/or other things going on in your application.
You can find more information on using the profiler with parallel applications here:
http://msdn.microsoft.com/en-us/library/ff963545.aspx