From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fa528,bc5b0be4bdad749d X-Google-Attributes: gidfa528,public X-Google-Thread: ffc1e,bc5b0be4bdad749d X-Google-Attributes: gidffc1e,public X-Google-ArrivalTime: 2001-08-13 04:29:58 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!paloalto-snf1.gtei.net!news.gtei.net!news.compaq.com!news.cpqcorp.net!not-for-mail From: David Butenhof Subject: Re: mutex problem using DECthreads Newsgroups: comp.programming.threads,comp.unix.tru64 Followup-To: comp.programming.threads References: <3B77796D.6218EA20@ot.com.au> User-Agent: KNode/0.4 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit Message-ID: <2JOd7.37$bB1.9242@news.cpqcorp.net> Date: Mon, 13 Aug 2001 07:19:26 -0400 NNTP-Posting-Host: 16.31.48.112 X-Complaints-To: abuse@Compaq.com X-Trace: news.cpqcorp.net 997701566 16.31.48.112 (Mon, 13 Aug 2001 04:19:26 PDT) NNTP-Posting-Date: Mon, 13 Aug 2001 04:19:26 PDT Organization: Compaq Computer Corporation Xref: archiver1.google.com comp.programming.threads:5398 comp.unix.tru64:4165 Raj Calisa wrote: > I am using DECthreads on Digital Unix 4.0F (patch kit 5). Although this should be completely irrelevant, you should consider installing patch kit 6, which has been out since February. > In our, application, one of our threads cause the application > to crash due to an assertion failure. This happens when it tries > to acquire a mutex and it fails. This mutex happens to be a static > mutex. It is wrapped up in a C++ class which is created statically. > The mutex itself is created in the constructor of the class using > pthread_mutex_init() rather than PTHREAD_MUTEX_INITIALIZER. I > remember reading somewhere that all static mutexes must be initialized > using the macro and non-static ones with the init() function, otherwise > one would get undefined behaviour. > Is this true? You cannot statically initialize a dynamically allocated mutex, even where the language would allow the syntax. For example, a local variable in a procedure cannot be statically initialized with PTHREAD_MUTEX_INITIALIZER, even though the compiler will happily apply the syntax. It's fine, however, to dynamically initialize any mutex, no matter where it's been allocated... as long as it hasn't previously been initialized (or has been destroyed since an earlier initialization). > If so, does a mutex wrapped into a class whose object gets created > statically qualify as a static mutex? If the storage for the mutex is allocated by the compiler, rather than at runtime, then it's "static". In C, that covers variables declared with the keyword "static", or (explicitly or implicitly) with the keyword "extern". Anything else is dynamic -- stack allocations via local variable declarations, heap (new) allocations, etc. The C++ "static" is similar, though not quite the same. Still, even in a "static" object, you may have pointers to dynamically allocated objects. You don't say enough about your program's structure to answer your question with any certainty. > I checked the documentation in pthread.h and it says that the "sequence" > field of the mutex object is set to 0 initially for static mutexes > initialized with the macro and to some non-zero value for the one > created using the init() call. A statically initialized mutex (PTHREAD_MUTEX_INITIALIZER) will be "completed" the first time it's used by the program. By the way, the implementation commentary in pthread.h is there to be nice, but, technically, it's not formal "documentation". Nothing you learn from it should ever be used in a program, because most of it can change without notice at any time. > The mutex in question is presumably static, but initialized with > the init() call and has a sequence number of "0" when I checked it > under the debugger. The "lock" field wass having a bad value as well, > which explains why mutex_lock() failed. "Presumably" static? What does THAT mean? Either it's static or it's not; if this is your program you can tell by reading the source. > Is DECthreads doing something consciously to reject the call to > pthread_mutex_init()? I am not ruling out memory corruption, but > I would like to explore other possibilities before delving into > that one. Are you checking for pthread_mutex_init() failure? What do you DO if it fails? For that matter, how is pthread_mutex_lock() failing? Finally... while you can explore other possibilities as much as you'd like, your problem is most likely to be memory corruption. Running with Visual Threads may help you find a problem, if its caused by improper synchronization. You can get more info, and the latest kit, at http://www.compaq.com/products/software/visualthreads/. /------------------[ David.Butenhof@compaq.com ]------------------\ | Compaq Computer Corporation POSIX Thread Architect | | My book: http://www.awl.com/cseng/titles/0-201-63392-2/ | \-----[ http://home.earthlink.net/~anneart/family/dave.html ]-----/