[swift-dev] pthread_mutex vs std::mutex

Joe Groff jgroff at apple.com
Fri Feb 26 13:08:26 CST 2016


> On Feb 26, 2016, at 10:35 AM, John McCall via swift-dev <swift-dev at swift.org> wrote:
> 
>> On Feb 25, 2016, at 5:51 PM, Sangjin Han via swift-dev <swift-dev at swift.org> wrote:
>> I'm a newbie in this world. I have a qustion.
>> 
>> Is there any reason to prefer pthread_mutex_* to std::mutex in the swift stdlib ?
>> 
>> Nowadays in C++, the std::mutex is the standard and more portable than pthread_mutex_*.
>> 
>> If I'm porting the swift stdlib to non-POSIX system, which method should I choose ?
>> 
>> Adding #if-#else-#endif or changing pthread to std::mutex ?
> 
> The runtime already uses std::mutex in a few places, so if there were portability problems with it, we’d already be hitting them.  I agree that we should prefer std::mutex where possible.

We should definitely standardize on one or the other, at least. std::mutex would definitely make things easier for ports to less POSIXish platforms.

-Joe


More information about the swift-dev mailing list