Date: Wed, 15 May 2013 17:06:44 +0800 From: David Xu <davidxu@freebsd.org> To: Poul-Henning Kamp <phk@freebsd.org> Cc: threads@freebsd.org Subject: Re: pthread_key_create() should avoid key#0 Message-ID: <51935024.3080107@freebsd.org> In-Reply-To: <79159.1368525129@critter.freebsd.dk> References: <79159.1368525129@critter.freebsd.dk>
next in thread | previous in thread | raw e-mail | index | archive | help
On 2013/05/14 17:52, Poul-Henning Kamp wrote: > > I think this patch would be a good idea, it avoids allocing > a thread specific key with numeric value zero, which helps > expose cases where a key hasn't been allocated in the first > place. > > > Index: libkse/thread/thr_spec.c > =================================================================== > --- libkse/thread/thr_spec.c (revision 248293) > +++ libkse/thread/thr_spec.c (working copy) > @@ -59,7 +59,7 @@ > > /* Lock the key table: */ > THR_LOCK_ACQUIRE(curthread, &_keytable_lock); > - for (i = 0; i < PTHREAD_KEYS_MAX; i++) { > + for (i = 1; i < PTHREAD_KEYS_MAX; i++) { > > if (_thread_keytable[i].allocated == 0) { > _thread_keytable[i].allocated = 1; > @@ -84,7 +84,7 @@ > struct pthread *curthread = _get_curthread(); > int ret = 0; > > - if ((unsigned int)key < PTHREAD_KEYS_MAX) { > + if (key > 0 && (unsigned int)key < PTHREAD_KEYS_MAX) { > /* Lock the key table: */ > THR_LOCK_ACQUIRE(curthread, &_keytable_lock); > > Index: libthr/thread/thr_spec.c > =================================================================== > --- libthr/thread/thr_spec.c (revision 248293) > +++ libthr/thread/thr_spec.c (working copy) > @@ -61,7 +61,7 @@ > > /* Lock the key table: */ > THR_LOCK_ACQUIRE(curthread, &_keytable_lock); > - for (i = 0; i < PTHREAD_KEYS_MAX; i++) { > + for (i = 1; i < PTHREAD_KEYS_MAX; i++) { > > if (_thread_keytable[i].allocated == 0) { > _thread_keytable[i].allocated = 1; > @@ -86,7 +86,7 @@ > struct pthread *curthread = _get_curthread(); > int ret = 0; > > - if ((unsigned int)key < PTHREAD_KEYS_MAX) { > + if (key > 0 && (unsigned int)key < PTHREAD_KEYS_MAX) { > /* Lock the key table: */ > THR_LOCK_ACQUIRE(curthread, &_keytable_lock); > > while key#0 is avoided, I would like to see we still support PTHREAD_KEYS_MAX keys. I am working on it.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?51935024.3080107>