Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 12 Oct 2000 21:44:46 -0700
From:      Jason Evans <jasone@canonware.com>
To:        Terry Lambert <tlambert@primenet.com>
Cc:        Alfred Perlstein <bright@wintelcom.net>, Chuck Paterson <cp@bsdi.com>, Mike Smith <msmith@FreeBSD.ORG>, arch@FreeBSD.ORG
Subject:   Re: we need atomic_t
Message-ID:  <20001012214446.H11949@canonware.com>
In-Reply-To: <200010130251.TAA03945@usr05.primenet.com>; from tlambert@primenet.com on Fri, Oct 13, 2000 at 02:51:31AM %2B0000
References:  <20001012192229.F272@fw.wintelcom.net> <200010130251.TAA03945@usr05.primenet.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, Oct 13, 2000 at 02:51:31AM +0000, Terry Lambert wrote:
> > The reason for atomic_init/destroy is to intialize mutexes if they
> > are needed on the arch.  Basically atomic64_t on 32bit arches would
> > be a struct with a 64bit value and a mutex to protect it.
> 
> Tee hee hee.
> 
> How do I initialize the mutex that protects the mutex?
> 
> I think it's time to learn from the POSIX threads mutex
> implementation, wherein it is impossible to statically
> initialize a mutex, and to obtain that appearance, you
> have to trick the loader into doing the work using the
> section which is used for the construction of virtual
> base classes in C++ (see my modifications to the STL, as
> applied to the Moscow Center for Supercomuting Activites
> STL, which is the most up to date STL available).

Here's one of Butenhof's example programs, which uses POSIX threads:
-------------------------------------------------------------------------
/*
 * mutex_static.c
 *
 * Demonstrate static initialization of a mutex.
 */
#include <pthread.h>

/*
 * Declare a structure, with a mutex, statically initialized. This is the
 * same as using pthread_mutex_init, with the default attributes.
 */
typedef struct my_struct_tag {
    pthread_mutex_t     mutex;  /* Protects access to value */
    int                 value;  /* Access protected by mutex */
} my_struct_t;

my_struct_t data = {PTHREAD_MUTEX_INITIALIZER, 0};

int main (int argc, char *argv[])
{   
    return 0;
}
-------------------------------------------------------------------------

That looks like static mutex initialization to me. =)

Jason


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20001012214446.H11949>