主线程和子线程之间的通信没有子线程终止 [英] communication between main thread and child thread without child thread terminating

查看:92
本文介绍了主线程和子线程之间的通信没有子线程终止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的程序中添加几个主题。 但我不希望那些任务完成时终止。 我希望那些任务完成时让他们睡觉。   然后主线程将唤醒线程以执行下一个任务。  1. 
主线程如何在唤醒它以启动下一个任务时将参数传递给子线程?   一旦线程完成任务,如何在返回睡眠状态之前将返回值传递回主线程(无需终止)。  3. 
子线程如何告诉主线程在进入睡眠状态之前完成任务?

I want to have few threads in my program.  But I don't want those to terminate when there tasks are done.  i rather want those to sleep when the tasks are done.   Main thread will then wake up the thread for the next tasks.  1.  How can main thread can pass parameters to child thread while waking it up to start the next task?   Once thread has done task, how can it pass the return value back to main thread before going to sleep (without terminating).  3.  How can child thread tells main thread that it is done with the task before going to sleep?

我不希望线程终止,因为它们可以在自己的大对象上工作和数据库连接。 终止和启动每个任务的线程将是非常昂贵的。   

I do not want threads to terminate as they will work on their own big objects and database connections.  terminating and starting thread for each task would be very costly.  

推荐答案

也许你正在寻找这个 - -
线程池

Perhaps you are looking for this -- Thread Pools


这篇关于主线程和子线程之间的通信没有子线程终止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆