且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如果第二个线程等待第一个线程的终止,是否需要内存屏障?

更新时间:2022-06-25 23:23:59

几乎可以肯定(用于等待线程终止的 API 需要为自己的目的使用内存屏障),但我认为你会得到一个明确的答案需要谈谈正在使用的特定线程API.

Almost certainly (the API used to wait for thread termination would need to use memory barriers for its own purposes), but I think for a definitive answer you'll need to talk about the specific threading API being used.

例如,posix 为 pthread_join() 做出这样的保证:https://***.com/a/3208140/12711

For example, posix makes such a guarantee for pthread_join(): https://***.com/a/3208140/12711

Win32 记录了等待对象(例如,线程句柄)的同步 API 强加了内存屏障:http://msdn.microsoft.com/en-us/library/ms686355.aspx

And Win32 documents that it's synchronization APIs to wait on an object (for example, a thread handle) impose memory barriers: http://msdn.microsoft.com/en-us/library/ms686355.aspx