[15] in Pthreads mailing list archive

home help back first fref pref prev next nref lref last post

Re: Two new functions for pthread

daemon@ATHENA.MIT.EDU (Stephen P Spackman)
Tue Jun 13 05:17:01 1995

To: hjl@nynexst.com (H.J. Lu)
Cc: proven@MIT.EDU, pthreads@MIT.EDU
In-Reply-To: Your message of "Mon, 12 Jun 95 23:46:47 EDT."
             <m0sLMwC-0001VbC@didi.nynexst.com> 
Date: Tue, 13 Jun 95 10:35:01 +0200
From: Stephen P Spackman <spackman@dfki.uni-sb.de>

|While putting pthreads into the Linux C library, I found out I need
|those two functions. I added them to the pthreads library. The
|idea is the C library should not know the internal structure of
|pthreads. Pointers are ok. But Structures are not.

You take a minor performance hit here because malloc() needs to
synchronise. More important, your "__pthread_mutex_free" is incorrect,
if it is supposed to be the dual of __pthread_mutex_malloc: it forgets
to destroy the mutex before releasing its storage. You have no way of
knowing whether a mutex uses allocated storage (or some other global
resource) internally, or not.

(Of course, if you are willing to assume that you have full knowledge of
the structures used to implement mutexes, this may be irrelevant. But if
the library doesn't want to know the internal structure of pthreads
objects....).

Regards
stephen
----------------------------------------------------------------------
stephen p spackman    +49 681 302 5288(o) 5282(sec)    stephen@acm.org
  dfki +1.24 / stuhlsatzenhausweg 3 / D-66123 saarbruecken / germany
----------------------------------------------------------------------
|#include <pthread.h>
|#include <malloc.h>
|
|pthread_mutex_t *
|__pthread_mutex_malloc (const pthread_mutexattr_t *attr)
|{
|  pthread_mutex_t *mutex =
|	(pthread_mutex_t*) malloc (sizeof (pthread_mutex_t));
|
|  if (mutex)
|  {
|    pthread_mutex_init (mutex, attr);
|  }
|  return mutex;
|}
|
|void
|__pthread_mutex_free (pthread_mutex_t *mutex)
|{
   pthread_mutex_destroy(*mutex);		/* sps */
|  free (mutex);
|}


home help back first fref pref prev next nref lref last post