From owner-freebsd-arch Thu Oct 12 21:45: 3 2000 Delivered-To: freebsd-arch@freebsd.org Received: from magnesium.net (toxic.magnesium.net [207.154.84.15]) by hub.freebsd.org (Postfix) with SMTP id 847BA37B502 for ; Thu, 12 Oct 2000 21:44:58 -0700 (PDT) Received: (qmail 25149 invoked by uid 1142); 13 Oct 2000 04:44:57 -0000 Date: 12 Oct 2000 21:44:57 -0700 Date: Thu, 12 Oct 2000 21:44:46 -0700 From: Jason Evans To: Terry Lambert Cc: Alfred Perlstein , Chuck Paterson , Mike Smith , arch@FreeBSD.ORG Subject: Re: we need atomic_t Message-ID: <20001012214446.H11949@canonware.com> References: <20001012192229.F272@fw.wintelcom.net> <200010130251.TAA03945@usr05.primenet.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <200010130251.TAA03945@usr05.primenet.com>; from tlambert@primenet.com on Fri, Oct 13, 2000 at 02:51:31AM +0000 Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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 /* * 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