开发者

Event Handling of Threads in Objective C

开发者 https://www.devze.com 2023-03-07 22:28 出处:网络
I am new to programming.Event handling in thread can be done through Run Loops in Objective C. I have to do createEvent,ResetEvent,PulseEvent,BeginThread,wa开发者_C百科itforsingleObject.

I am new to programming.Event handling in thread can be done through Run Loops in Objective C.

I have to do createEvent,ResetEvent,PulseEvent,BeginThread,wa开发者_C百科itforsingleObject.

How to do this in Objective C. Is there any material that explains well about these concepts with example other than apple docs.


Really not a lot of information to go on here, but heres some ideas that came to mind when reading your post.

I see three approches to this:

1) Dictionary of arrays of blocks where the key in the dictionary is the event being fired and then when the event manager gets the event it cycles over the array for that key and runs all the blocks

2) Set up a KVO system where your events are your keys/values and your observers are your handlers

3) setup a delegate-protocol system so that your delegate is your handler and your protocol maps the events that can be fired

all have pros and cons, I tend toward 1 and 3 myself, but hope that helps!


I assume question is related to the porting of Windows source code to Mac or iOS.

Not really full answer but you can start from here.

CreateEvent, ResetEvent, WaitForSingleObject => NSCondition Class Reference

Event is the unique feature of Windows but reasonably replaced with NSCondtion.

BeginThread => NSThread Class Reference
More specifically + (void)detachNewThreadSelector:(SEL)aSelector toTarget:(id)aTarget withObject:(id)anArgument method.

AfxBeginThread(WorkerThreadProc,NULL,THREAD_PRIORITY_NORMAL,0,0,NULL);
=>
[NSThread detachNewThreadSelector:@selector(WorkerThreadProc:) toTarget:self withObject:NULL];

PulseEvent is very difficult to port to Mac or iOS.

0

精彩评论

暂无评论...
验证码 换一张
取 消