在Wine中,互斥锁如何比Linux上的本地互斥锁更快?

2作者: lh_mouse11 天前原帖
系统信息 * CPU: 11代英特尔酷睿i7-1165G7 * 系统: Linux Mint 22.2 * 内核: 6.11.0-1014-lowlatency(无ntsync) * 系统libc: GNU C库 2.39 * Wine: 9.0 * 编译器: GCC 13(均可) 配置和执行时间(时间越短越好) * linux std: (8.150秒) std::mutex,基于pthread * linux boost: (10.936秒) boost::mutex * win std: (20.246秒) std::mutex,基于CRITICAL_SECTION * win boost: (4.849秒) boost::mutex * win srw: (15.853秒) SRWLOCK * win mcf0i: (4.117秒) 来自mcfgthread的_MCF_mutex,内联禁用 该测试使用的代码来自 https://github.com/markwaterman/MutexShootout Hyperfine 截图: https://files.lhmouse.com/20250826-155709.png 当boost::mutex本地编译时,其速度比glibc慢,但当它为Windows编译并在Wine中运行时,其性能超过了除mcfgthread之外的所有选项,包括本地的glibc互斥锁。这是否意味着glibc互斥锁在设计上较差,还是Wine中的线程调度有某种魔力,使得boost::mutex在此测试中表现更佳?
查看原文
System information<p>* CPU: 11th Gen Intel Core i7-1165G7<p>* System: Linux Mint 22.2<p>* Kernel: 6.11.0-1014-lowlatency (no ntsync)<p>* Sys libc: GNU C library 2.39<p>* Wine: 9.0<p>* Compiler: GCC 13 (both)<p>Configurations and time of execution (lower is better)<p>* linux std: ( 8.150 s) std::mutex, backed by pthread<p>* linux boost: (10.936 s) boost::mutex<p>* win std: (20.246 s) std::mutex, backed by CRITICAL_SECTION<p>* win boost: ( 4.849 s) boost::mutex<p>* win srw: (15.853 s) SRWLOCK<p>* win mcf0i: ( 4.117 s) _MCF_mutex from mcfgthread, inlining disabled<p>The test uses code from https:&#x2F;&#x2F;github.com&#x2F;markwaterman&#x2F;MutexShootout<p>Hyperfine screenshot: https:&#x2F;&#x2F;files.lhmouse.com&#x2F;20250826-155709.png<p>When boost::mutex is compiled natively it&#x27;s slower than glibc, but when it&#x27;s compiled for Windows and run in Wine it outperforms everything except mcfgthread, including native glibc mutex. Does this mean the glibc mutex is inferior in design, or is it sorta magic in thread scheduling in Wine that makes boost::mutex behave better in this test?