Boost logo

Boost :

From: Kevin Atkinson (kevin_at_[hidden])
Date: 2003-02-19 19:26:09

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:

  static const pthread_mutex_t MUTEX_INIT = PTHREAD_MUTEX_INITIALIZER;

  class Mutex {
    pthread_mutex_t l_;
    Mutex(const Mutex &);
    void operator=(const Mutex &);
    Mutex() : l_(MUTEX_INIT) {}
    Mutex() {pthread_mutex_init(&l_, 0);}
    ~Mutex() {pthread_mutex_destroy($l_);}
    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.


Boost list run by bdawes at, gregod at, cpdaniel at, john at