[swift-dev] pthread_mutex vs std::mutex

Dmitri Gribenko gribozavr at gmail.com
Thu Feb 25 23:01:22 CST 2016


On Thu, 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 ?

I don't think there is a problem with using std::mutex, but I know
that you will encounter issues down the road (in tests and other
places) that use pthreads.  It will be a massive task to port them.
You might consider writing a shim library implementing the required
parts of pthreads instead.

Dmitri

-- 
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/


More information about the swift-dev mailing list