|
Boost : |
From: Kevin Atkinson (kevin_at_[hidden])
Date: 2003-02-19 21:21:49
On Wed, 19 Feb 2003, Kevin Atkinson wrote:
> On Wed, 19 Feb 2003, Alexander Terekhov wrote:
>
> > struct pthread_mutex_t_ {
> >
> > /* ... */
> >
> > #ifdef __cplusplus
> >
> > __copy_ctor(const pthread_mutex_t_&) {
> > throw "Don't do this!";
> > }
> >
> > #endif
> >
> > };
> > typedef struct pthread_mutex_t_ pthread_mutex_t;
>
> I do not know where it is implemented, it is not on my system, this way
> but I think what I did should be perfectly legal as I am merely initializing
> the class. In fact having ANY constructor will prevent the statement
> "pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER" from working on my
> system and probably others which IS legal. This is because if you have ANY
> contractor defined and PTHREAD_MUTEX_INITIALIZER is a macro which uses the
> "{...}" form you will get something like this "...must be initialized by
> constructor, not by `{...}'.
>
> I have changed the definition to:
>
> #ifdef FAST_MUTEX_INIT_DESTROY
> static const pthread_mutex_t MUTEX_INIT = PTHREAD_MUTEX_INITIALIZER;
> #endif
>
> class Mutex {
> pthread_mutex_t l_;
> private:
> Mutex(const Mutex &);
> void operator=(const Mutex &);
> public:
> #ifdef FAST_MUTEX_INIT_DESTROY
> Mutex() : l_(MUTEX_INIT) {}
> #else
> Mutex() {pthread_mutex_init(&l_, 0);}
> ~Mutex() {pthread_mutex_destroy($l_);}
That '$' should be a '&'. Sorry I didn't actually try to compile it.
> #endif
> void lock() {pthread_mutex_lock(&l_);}
> void unlock() {pthread_mutex_unlock(&l_);}
> };
>
> I hope your happy now. So stupid systems that have pthread_mutex_t
> defined that way will work.
>
> Anyway. My locking primitives are designed to be on top of any locking
> mechanism, so this is a minor issue.
-- http://kevin.atkinson.dhs.org
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk