为什么多线程应用程序不使用100%的CPU

时间:2019-06-01 14:43:51

标签: c++ multithreading cpu-usage

我创建了一个生活游戏:(https://gitlab.com/kiroma/gol-proto),我尝试使用可扩展线程池进行多线程处理。从理论上讲,它应该尽可能多地使用所有内核,但是无论模拟大小如何,该平台(在Linux机器,2c / 4t和Windows机器4c / 4t上进行测试)都不会使用超过60的内核。占整个CPU运行时间的百分比。

使用自旋锁而不是等待条件变量进行同步来更改进程优先级,排除诸如缓存争用之类的悲观行为。

对于该项目,我创建了自己的线程池类,称为工作池:(https://gitlab.com/kiroma/gol-proto/blob/master/workpool.cpp)。像将 #PAGESPEED pagespeed on; # Needs to exist and be writable by nginx. Use tmpfs for best performance. pagespeed FileCachePath /var/ngx_pagespeed_cache; # Ensure requests for pagespeed optimized resources go to the pagespeed handler # and no extraneous headers get set. location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" { access_log off; expires 365d; add_header ETag ""; add_header Pragma public; add_header Cache-Control "max-age=31449600, no-transform, public"; try_files $uri $uri/ @rewrite; } location ~ "^/pagespeed_static/" { } location ~ "^/ngx_pagespeed_beacon$" { } pagespeed EnableFilters extend_cache; pagespeed EnableCachePurge on; pagespeed PurgeMethod PURGE; pagespeed HonorCsp on; pagespeed RespectVary on; pagespeed DisableRewriteOnNoTransform off; pagespeed LowercaseHtmlNames on; pagespeed InPlaceResourceOptimization on; pagespeed InPlaceRewriteDeadlineMs 100; pagespeed PreserveUrlRelativity on; pagespeed XHeaderValue "powered by ngx_pagespeed"; pagespeed EnableFilters collapse_whitespace; pagespeed EnableFilters convert_meta_tags; pagespeed EnableFilters remove_comments; pagespeed EnableFilters fallback_rewrite_css_urls; #javascript pagespeed EnableFilters rewrite_javascript; pagespeed EnableFilters inline_javascript; pagespeed EnableFilters combine_javascript; pagespeed Disallow "*/analytics.js"; pagespeed Disallow "*analytics.js"; pagespeed Disallow "https://www.example.com/sites/default/files/googleanalytics/analytics.js"; #analytics pagespeed EnableFilters make_google_analytics_async; #images pagespeed EnableFilters rewrite_images; pagespeed EnableFilters resize_images; pagespeed DisableFilters inline_images; pagespeed DisableFilters resize_rendered_image_dimensions; pagespeed DisableFilters sprite_images; pagespeed EnableFilters recompress_images; pagespeed EnableFilters insert_image_dimensions; pagespeed EnableFilters convert_to_webp_lossless; #css pagespeed EnableFilters move_css_to_head; pagespeed EnableFilters rewrite_css; pagespeed EnableFilters inline_css; pagespeed EnableFilters prioritize_critical_css; pagespeed EnableFilters combine_css; pagespeed MaxCombinedCssBytes -1; #pagespeed CssFlattenMaxBytes 4096; pagespeed CssInlineMaxBytes -1; pagespeed CssImageInlineMaxBytes -1; pagespeed CssOutlineMinBytes 3000; std::condition_variable_any一起使用有一些奇怪之处,但是我尝试了其他更常规的方法,结果大致相同。

0 个答案:

没有答案