Boost logo

Boost :

From: Alexander Terekhov (terekhov_at_[hidden])
Date: 2003-02-20 04:22:59


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 `{...}'.

Nah. That doesn't apply the "__" constructor(s). ;-)

>
> I have changed the definition to:
>
> #ifdef FAST_MUTEX_INIT_DESTROY
                         ^^^^^^^

> static const pthread_mutex_t MUTEX_INIT = PTHREAD_MUTEX_INITIALIZER;

Uhmm. What does your "fast destruction" do? Well, looking at the code
you've posted, it does nothing... and that's the "fastest" way to leak.

> #endif

Get rid of it. Really.

Here's another "example":

  struct pthread_mutex_t_ {

    void* validation_sentinel;

    /* ... */

 };
 typedef struct pthread_mutex_t_ pthread_mutex_t;

 #define PTHREAD_MUTEX_INITIALIZER { &__aggregate /* ... */ }

regards,
alexander.


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