Boost logo

Boost :

Subject: Re: [boost] [thread/interprocess] [repost] could we improve recursive_mutex constructor
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2009-01-24 06:47:22


Hello, I first posted this six months ago, allow me to repost just in
case it went unnoticed:

----- Original Message -----
From: "vicente.botet" <vicente.botet_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Wednesday, June 18, 2008 3:33 PM
Subject: [boost] [thread/interprocess] could we improve recursive_mutexconstructor

>
> Hi,
>
> the recursive_mutex constructor initialize/set/destroy the
> pthread_mutexattr_t every time.
> I'm wondering if we can improve the efficiency storing this on a static
> variable which will be initialized once.
> What could be the better way to initialize this static variable?
>
> Note: the same applies to interprocess mutexes.
>
> recursive_mutex()
> {
> // begin code that can be initialized only once
> pthread_mutexattr_t attr;
> int const init_attr_res=pthread_mutexattr_init(&attr);
> if(init_attr_res)
> {
> throw thread_resource_error();
> }
> int const
> set_attr_res=pthread_mutexattr_settype(&attr,PTHREAD_MUTEX_RECURSIVE);
> if(set_attr_res)
> {
> throw thread_resource_error();
> }
> // end code that can be initialized only once
> int const res=pthread_mutex_init(&m,&attr);
> if(res)
> {
> throw thread_resource_error();
> }
> // begin code that can be removed
> BOOST_VERIFY(!pthread_mutexattr_destroy(&attr));
> // end code that can be removed
> }
>
> Regards,
>
> Vicente
>
>
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk