[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Thred, Sockets, timers and runloop
From: |
Richard Frith-Macdonald |
Subject: |
Re: Thred, Sockets, timers and runloop |
Date: |
Fri, 27 Apr 2001 11:23:01 +0100 |
On Friday, April 27, 2001, at 10:51 AM, Manuel Guesdon wrote:
I work on a gsweb application which should handle and timers in a
different threads.
basically gsweb create a NSFileHandle like that
[NSFileHandle fileHandleAsServerAtAddress:host
service:[NSString
stringWithFormat:@"%d",port]
protocol:@"tcp"] retain];
and wait for NSFileHandleConnectionAcceptedNotification notification
in my application, I create a new thread ( [NSThread
detachNewThreadSelector:@selector(runTimerThread:)
toTarget:self
withObject:nil]) and add timers.
Now I want that this thread handle timers ticks and that the main
thread still responds to incoming connections.
I've tried many things these last days (and found strange problems) but
none worked.
Any idea about how to do this ?
There is one default NSRunLoop instance per thread.
If you schedule a timer, it is added to the current runloop (unless you
create an instance and
add it to a particular runloop).
This means that timers are thread specific, and they only fire if the
runloop that they were
added to is in use.
So what you have described should work ... your timer thread would
create the timers then
enter the runloop and run indefinately. As timers fire it should send
notifications.
As there is only one notification center, the observer registered in
another thread should
still see the notification.
You don't actually say what the problem is ... if you could produce a
small testcase demonstrating
it, I could try debugging.