[basic-improvements] Remove __gthread_key_dtor

Eric Christopher echristo@redhat.com
Mon Nov 4 12:11:00 GMT 2002


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...



More information about the Gcc-patches mailing list