[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: NSThread limits?
From: |
Sašo Kiselkov |
Subject: |
Re: NSThread limits? |
Date: |
Mon, 07 Apr 2008 16:31:39 +0200 |
User-agent: |
Thunderbird 2.0.0.12 (X11/20080227) |
The problem you're experiencing is because GNUstep's runtime creates
threads with a detach state of PTHREAD_CREATE_JOINABLE, which don't
release the resources associated with the thread until another thread
calls a pthread_join() on the terminated thread in order to collect its
return status. Which is kind of a bug in GNUstep, because you have no
way of joining it manually.
Your best bet is creating the thread manually, not using the NSThread
API. I use the following code snippet to do the trick:
pthread_t thread;
pthread_attr_t attrs;
if ((code = pthread_attr_init (&attrs)))
{
// Error initializing thread attributes
}
if ((code = pthread_attr_setdetachstate (&attrs, PTHREAD_CREATE_DETACHED)))
{
// Error setting thread attributes
}
if ((code = pthread_create (&thread, &attrs, ThreadFuncCallback, NULL)))
{
// Error creating thread
}
This has worked for me with thousands of threads being created and
terminated.
--
Saso
Marc Wan wrote:
> hello!
>
> I am looking to create a server that maintains a pool of a few
> hundred threads at a time, and being a fan of objective-c, i had hoped
> to be able to use GNUStep to do this on non-mac platforms.
>
> unfortunately, I don't seem to be able to fork more than about
> 150-160 threads using
> NSThread::detachNewThreadSelector:toTarget:withObject. on my macs
> here, i can easily do 1000 (i didn't test higher).
>
> after this on Linux, I get:
>
> : Uncaught exception NSInternalInconsistencyException, reason: Unable
> to detach thread (unknown error)
>
>
> i had worried that this was a linux (ubuntu 6.10 LTS Server) issue,
> but /proc/sys/kernel/thread-max says that it'll handle over 143000
> threads ... some casual browsing of NSThread.m didn't immediately show
> any limitations.
>
> any idea why this might be happening?
>
> thanks,
> mark.
>
>
> _______________________________________________
> Gnustep-dev mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/gnustep-dev
>