public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Eric Christopher <echristo@redhat.com>
To: Zack Weinberg <zack@codesourcery.com>
Cc: Richard Henderson <rth@redhat.com>, gcc-patches@gcc.gnu.org
Subject: Re: [basic-improvements] Remove __gthread_key_dtor
Date: Mon, 04 Nov 2002 12:11:00 -0000	[thread overview]
Message-ID: <1036442469.1509.22.camel@ghostwheel> (raw)
In-Reply-To: <20021101001223.GK5766@codesourcery.com>

Zack,

> 
> > static void *key_value[THR_ID_NUM][KEY_NUM] = { { 0 }, { 0 } };
> > static int   key_use[KEY_NUM] = { 0 };
> > 
> > /* Mutex for locking key bitmap.  */
> > static __gthread_mutex_t key_mutex;
> 
> There needs to be just one version of these variables, but gthr.h is
> included all over the place - this needs to go out-of-line, into a
> libgcc.a extra part, probably along with the code that uses it.
> 

Hrm. I was noticing that other ports use this method and that's why I
did - I also didn't see a way for it to work otherwise since there's no
general .c mechanism for it.

> I take it there can be only 256 threads?
> 

Heh. Threads? No. I've got semaphores and only semaphores.

> > static inline int
> > __gthread_once (__gthread_once_t *once, void (*func) ())
> > {
> >   return 0;
> > }
> 
> You're going to want a real version of this function.  It's used in
> the unwinder, but also...
> 

OK.

> > static inline int
> > __gthread_key_create (__gthread_key_t *keyp, void (*dtor) (void *))
> > {
> >   int i;
> > 
> >   __gthread_mutex_lock (&key_mutex);
> >   for (i = 0; i < KEY_NUM; i++)
> >     {
> >       if (!key_use[i] && dtor != 0)
> >         {
> >           key_use[i] = 1;
> >           __gthread_mutex_unlock (&key_mutex);
> >           *keyp = i;
> >           return 0;
> >         }
> >     }
> >   __gthread_mutex_unlock (&key_mutex);
> >   return -1;
> > }
> 
> where does key_mutex get initialized?  I have the same requirement on
> mutexes in VxWorks (must use an initialization function) and wound up
> using __gthread_once to call __gthread_mutex_init_function on the
> mutex used to protect the keys table.
> 

oops. thanks :)

> There is no requirement that dtor be nonzero, and you threw away its
> value; this will cause memory leaks.  You're going to need to find
> some way to get a callback run at thread exit time.  And that callback
> can do the clear-out-the-value thing.
> 

hrm. If I could do that I could also free semaphores which would help me
avoid the 253 limit that I currently have. I was under the impression
that this was not possible though - at least not without rewriting the
machinery. 

> > static inline int
> > __gthread_setspecific (__gthread_key_t key, const void *ptr)
> > {
> >   if (key > KEY_NUM || !key_use[key])
> >     return -1;
> > 
> >   key_value[GetThreadId ()][key] = (void *)ptr;
> >   return 0;
> > }
> 
> This races with key_delete.  You'll have to have it take the lock, too.
> 

Thanks.

-eric

-- 
Yeah, I used to play basketball...

  reply	other threads:[~2002-11-04 20:11 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-29 14:33 Zack Weinberg
2002-10-29 23:50 ` Mark Mitchell
2002-10-31 11:18 ` Richard Henderson
2002-10-31 11:42   ` Zack Weinberg
2002-10-31 13:02     ` Richard Henderson
2002-10-31 13:20       ` Zack Weinberg
2002-10-31 13:57         ` Eric Christopher
2002-10-31 16:12           ` Zack Weinberg
2002-11-04 12:11             ` Eric Christopher [this message]
2002-11-04 17:08               ` Zack Weinberg
2002-11-04 18:19                 ` Eric Christopher
2002-10-31 12:04   ` Jason R Thorpe
2002-10-31 13:59     ` Eric Christopher

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1036442469.1509.22.camel@ghostwheel \
    --to=echristo@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=rth@redhat.com \
    --cc=zack@codesourcery.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).