Objective C 中线程的事件处理
我是编程新手。线程中的事件处理可以通过 Objective C 中的运行循环来完成。
我必须执行createEvent、ResetEvent、PulseEvent、BeginThread、waitforsingleObject
。
如何在 Objective C 中做到这一点。 除了苹果文档之外,是否有任何材料可以通过示例很好地解释这些概念。
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,waitforsingleObject
.
How to do this in Objective C.
Is there any material that explains well about these concepts with example other than apple docs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里确实没有太多信息,但这是阅读您的文章时想到的一些想法。
我看到了三种方法:
1)块数组的字典,其中字典中的键是被触发的事件,然后当事件管理器获取事件时,它循环遍历该键的数组并运行所有块
2)设置建立一个 KVO 系统事件是你的键/值,你的观察者是你的处理程序
3) 设置一个 委托协议系统,这样你的委托就是你的处理程序,你的协议映射可以触发的事件,
都有优点和缺点,我自己倾向于 1 和 3,但希望有所帮助!
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!
我认为问题与将 Windows 源代码移植到 Mac 或 iOS 相关。
不是完整的答案,但你可以从这里开始。
CreateEvent、ResetEvent、WaitForSingleObject => NSCondition 类参考
Event
是 Windows 独有的功能,但可以合理地用 NSCondtion 代替。开始线程 => NSThread 类参考
更具体地说,
+ (void)detachNewThreadSelector:(SEL)aSelector toTarget:(id)aTarget withObject:(id)anArgument
方法。AfxBeginThread(WorkerThreadProc,NULL,THREAD_PRIORITY_NORMAL,0,0,NULL);
=>
[NSThread detachNewThreadSelector:@selector(WorkerThreadProc:) toTarget:self withObject:NULL];
PulseEvent 很难移植到 Mac 或 iOS。
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.