父线程内的子线程
您能帮我解决这个问题吗:
如何在父线程中创建子线程。并且只有在子线程终止后才应终止父线程。并且父线程只有在子线程完成后才完成。
Can you please help me in this:
How to create a child thread in a parent thread. And the parent thread should be terminated only after the child thread is terminated. and the parent thread is completed only after completing child thread.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
NSCondition
。让子线程发出终止条件信号。让家长等待。添加一个谓词(布尔值即可)来解决“虚假信号”问题。请参阅线程编程指南。Use
NSCondition
. Have the child thread signal the condition on termination. Have the parent wait on the condition. Add a predicate (a bool will do it) to work around the 'spurious signals' issues. See Using Conditions on the Threading Programming Guide.