Skip navigation.
 
mlRe: Using NSThreads in command-line apps
FROM : ben syverson
DATE : Thu May 15 21:53:29 2008

On May 15, 2008, at 2:25 PM, Bill Bumgarner wrote:

> Your main thread loop?
>
> If that is the design you want to use, then you can use NSLock -- 
> NSConditionLock, typically -- to do the synchronization between 
> threads.  If your loop really is running flat out, then using a 
> condition lock will be marginally faster.
>
> b.bum


Maybe... I should be more specific, so it's clear what I'm trying to 
do. The application is a lightweight HTTP server which reads requests 
on a socket and uses two or three worker threads to generate the 
responses. I'm using kqueue / kevent instead of the Cocoa stuff.

I have one thread which runs the server's infinite loop. It can't be 
the main thread, because it calls kevent, which doesn't return a value 
until there's an event. So that thread's loop stops while kevent is 
waiting.

When the server thread gets a complete request, it needs to be picked 
up by a worker thread. Perhaps the way to do this is with an 
NSConditionalLock? As in, the server thread would lock an 
NSMutableArray, add the new requests, and that would trigger the 
worker thread? If I go with that, I guess I wouldn't have to a 
performSelectorOnMainThread:...

I want to go with whatever will give me the best performance. (I know, 
I know, ObjC adds some overhead, but the advantages in readability 
outweigh the messaging overhead for me. If I need to recode some parts 
as ANSI later, I will.)

Thanks for all the responses so far!

- ben

Related mailsAuthorDate
mlUsing NSThreads in command-line apps ben syverson May 15, 20:42
mlRe: Using NSThreads in command-line apps Bill Bumgarner May 15, 20:47
mlRe: Using NSThreads in command-line apps Randall Meadows May 15, 20:49
mlRe: Using NSThreads in command-line apps Uli Kusterer May 15, 20:51
mlRe: Using NSThreads in command-line apps Jens Alfke May 15, 20:52
mlRe: Using NSThreads in command-line apps ben syverson May 15, 21:16
mlRe: Using NSThreads in command-line apps ben syverson May 15, 21:17
mlRe: Using NSThreads in command-line apps Bill Bumgarner May 15, 21:25
mlRe: Using NSThreads in command-line apps Bill Bumgarner May 15, 21:31
mlRe: Using NSThreads in command-line apps ben syverson May 15, 21:53
mlRe: Using NSThreads in command-line apps Jens Alfke May 15, 23:17
mlRe: Using NSThreads in command-line apps ben syverson May 16, 00:28
mlRe: Using NSThreads in command-line apps Sherm Pendley May 16, 00:31
mlRe: Using NSThreads in command-line apps Hamish Allan May 16, 00:33
mlRe: Using NSThreads in command-line apps ben syverson May 16, 00:40
mlRe: Using NSThreads in command-line apps Hamish Allan May 16, 01:06
mlRe: Using NSThreads in command-line apps Jens Alfke May 16, 03:02
mlRe: Using NSThreads in command-line apps ben syverson May 16, 06:50