diff options
author | mtm <mtm@FreeBSD.org> | 2003-05-25 22:40:57 +0000 |
---|---|---|
committer | mtm <mtm@FreeBSD.org> | 2003-05-25 22:40:57 +0000 |
commit | d8e0ed54e351db48278bd6693dde605fcda057df (patch) | |
tree | 8bc5a970789c8f2762484249a02b9ccd0ccb6ef6 /lib/libthr | |
parent | 54155a49a5a2b84f07b579c8e6af7e5f9c8e1d88 (diff) | |
download | FreeBSD-src-d8e0ed54e351db48278bd6693dde605fcda057df.zip FreeBSD-src-d8e0ed54e351db48278bd6693dde605fcda057df.tar.gz |
Return gracefully, rather than aborting, when the maximum concurrent
threads per process has been reached. Return EAGAIN, as per spec.
Approved by: re/blanket libthr
Diffstat (limited to 'lib/libthr')
-rw-r--r-- | lib/libthr/arch/i386/i386/_setcurthread.c | 11 | ||||
-rw-r--r-- | lib/libthr/arch/ia64/ia64/_curthread.c | 4 | ||||
-rw-r--r-- | lib/libthr/arch/sparc64/sparc64/_setcurthread.c | 4 | ||||
-rw-r--r-- | lib/libthr/thread/thr_create.c | 13 | ||||
-rw-r--r-- | lib/libthr/thread/thr_init.c | 3 | ||||
-rw-r--r-- | lib/libthr/thread/thr_private.h | 2 |
6 files changed, 27 insertions, 10 deletions
diff --git a/lib/libthr/arch/i386/i386/_setcurthread.c b/lib/libthr/arch/i386/i386/_setcurthread.c index 0483120..2cd27ca 100644 --- a/lib/libthr/arch/i386/i386/_setcurthread.c +++ b/lib/libthr/arch/i386/i386/_setcurthread.c @@ -87,13 +87,15 @@ _retire_thread(void *entry) } void * -_set_curthread(ucontext_t *uc, struct pthread *thr) +_set_curthread(ucontext_t *uc, struct pthread *thr, int *err) { union descriptor desc; void **ldt_entry; int ldt_index; int error; + *err = 0; + /* * If we are setting up the initial thread, the gs register * won't be setup for the current thread. In any case, we @@ -106,8 +108,11 @@ _set_curthread(ucontext_t *uc, struct pthread *thr) if (ldt_inited == NULL) ldt_init(); - if (ldt_free == NULL) - abort(); + if (ldt_free == NULL) { + /* Concurrent thread limit reached */ + *err = curthread->error = EAGAIN; + return (NULL); + } /* * Pull one off of the free list and update the free list pointer. diff --git a/lib/libthr/arch/ia64/ia64/_curthread.c b/lib/libthr/arch/ia64/ia64/_curthread.c index 3744f7c..6c3de0e 100644 --- a/lib/libthr/arch/ia64/ia64/_curthread.c +++ b/lib/libthr/arch/ia64/ia64/_curthread.c @@ -48,9 +48,9 @@ _retire_thread(void *v) } void * -_set_curthread(ucontext_t *uc, struct pthread *thread) +_set_curthread(ucontext_t *uc, struct pthread *thread, int *err) { - + *err = 0; if (uc != NULL) uc->uc_mcontext.mc_special.tp = (uint64_t)thread; else diff --git a/lib/libthr/arch/sparc64/sparc64/_setcurthread.c b/lib/libthr/arch/sparc64/sparc64/_setcurthread.c index 4f1a303..4c0fb88 100644 --- a/lib/libthr/arch/sparc64/sparc64/_setcurthread.c +++ b/lib/libthr/arch/sparc64/sparc64/_setcurthread.c @@ -48,9 +48,9 @@ _retire_thread(void *v) } void * -_set_curthread(ucontext_t *uc, struct pthread *thread) +_set_curthread(ucontext_t *uc, struct pthread *thread, int *err) { - + *err = 0; if (uc != NULL) uc->uc_mcontext.mc_global[6] = (uint64_t)thread; else diff --git a/lib/libthr/thread/thr_create.c b/lib/libthr/thread/thr_create.c index 3033421..5b0158d 100644 --- a/lib/libthr/thread/thr_create.c +++ b/lib/libthr/thread/thr_create.c @@ -116,7 +116,18 @@ _pthread_create(pthread_t * thread, const pthread_attr_t * attr, new_thread->ctx.uc_stack.ss_sp = new_thread->stack; new_thread->ctx.uc_stack.ss_size = pattr->stacksize_attr; makecontext(&new_thread->ctx, _thread_start, 0); - new_thread->arch_id = _set_curthread(&new_thread->ctx, new_thread); + new_thread->arch_id = _set_curthread(&new_thread->ctx, new_thread, &ret); + if (ret != 0) { + if (pattr->stackaddr_attr == NULL) { + /* XXX - We really need to decouple from this lock */ + DEAD_LIST_LOCK; + _thread_stack_free(new_thread->stack, + pattr->stacksize_attr, pattr->guardsize_attr); + DEAD_LIST_UNLOCK; + } + free(new_thread); + return (ret); + } /* Copy the thread attributes: */ memcpy(&new_thread->attr, pattr, sizeof(struct pthread_attr)); diff --git a/lib/libthr/thread/thr_init.c b/lib/libthr/thread/thr_init.c index 98b0eef..9c334da 100644 --- a/lib/libthr/thread/thr_init.c +++ b/lib/libthr/thread/thr_init.c @@ -162,6 +162,7 @@ _thread_init(void) size_t len; int mib[2]; sigset_t set; + int error; struct clockinfo clockinfo; struct sigaction act; @@ -221,7 +222,7 @@ _thread_init(void) memset(pthread, 0, sizeof(struct pthread)); _thread_initial = pthread; - pthread->arch_id = _set_curthread(NULL, pthread); + pthread->arch_id = _set_curthread(NULL, pthread, &error); /* Get our thread id. */ thr_self(&pthread->thr_id); diff --git a/lib/libthr/thread/thr_private.h b/lib/libthr/thread/thr_private.h index db2bab2..d8e37b4 100644 --- a/lib/libthr/thread/thr_private.h +++ b/lib/libthr/thread/thr_private.h @@ -711,7 +711,7 @@ char *ttyname_r(int, char *, size_t); void _cond_wait_backout(pthread_t); int _find_thread(pthread_t); pthread_t _get_curthread(void); -void *_set_curthread(ucontext_t *, struct pthread *); +void *_set_curthread(ucontext_t *, struct pthread *, int *); void _retire_thread(void *arch_id); void *_thread_stack_alloc(size_t, size_t); void _thread_stack_free(void *, size_t, size_t); |