delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2004/03/15/12:58:06

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Message-ID: <20040315175749.72734.qmail@web14525.mail.yahoo.com>
Date: Mon, 15 Mar 2004 18:57:49 +0100 (CET)
From: =?iso-8859-1?q?Adrian?= <jarfo AT yahoo DOT com>
Reply-To: adrian AT gps DOT tsc DOT upc DOT es
Subject: Checking initialization in phread_mutexattr_init
To: cygwin AT cygwin DOT com
MIME-Version: 1.0
Note-from-DJ: This may be spam

Dear developers
Dear Thomas

As Thomas Pfaff has commented in previous messages,
for example,
http://www.cygwin.com/ml/cygwin/2003-10/msg01227.html,
cygwin contains some code to check for an already
initialized mutex attr and other pthread types.

I would strongly recommed to remove those checks
because they are not 100% fiable and I think they
cause more problems than solve.

The proposed workaround (memset initalization) is OK
for new code (and people aware ot that), but does not
provide compatibility with standard code as
boost::threads.

I have had problems in complex programs using
boost::thread, but I have prepared the following two
simple examples in which the pthread_mutexattr_init()
fails

#include <assert.h>
#include <pthread.h>

void initstack()
{
  int magic = 0xdf0df049;
  int* p = &magic;
}
pthread_mutexattr_t my_pthread_mutexattr_init(int
type)
{
  pthread_mutexattr_t tmp;
  assert(pthread_mutexattr_init(&tmp) == 0);
  assert(pthread_mutexattr_settype(&tmp,
PTHREAD_MUTEX_DEFAULT) == 0);
  return tmp;
}

int main()
{
  initstack();
  pthread_mutexattr_t attr_error =
my_pthread_mutexattr_init(PTHREAD_MUTEX_ERRORCHECK);
  pthread_mutexattr_t attr_recur =
my_pthread_mutexattr_init(PTHREAD_MUTEX_RECURSIVE);
  pthread_mutexattr_destroy(&attr_error);
  pthread_mutexattr_destroy(&attr_recur);
  return 0;
}

The first call fails because the local variable
pthread_mutexattr_t tmp hapens to point to a integer
with the PTHREAD_MUTEXATTR_MAGIC value. (Murphy
related problem) 

Even if you do not call to initstack(), the second
call fails because the local variable tmp still
retains the value of the previous call. (and stills
points to a valid thread object).




___________________________________________________
Yahoo! Messenger - Nueva versión GRATIS
Super Webcam, voz, caritas animadas, y más...
http://messenger.yahoo.es

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019