许多过程由一个线程执行 [英] Many processes executed by one thread

查看:151
本文介绍了许多过程由一个线程执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是类似以下内容可能在C对Linux平台:
我有一个线程说阅读器系统调用(拦截系统调用)由应用程序进程进行。对于每个进程创建一个线程,它执行所需的系统调用,然后睡觉,直到带有这是由相应的应用程​​序的过程做了另一个系统调用唤醒它。当一个进程退出时,它的工作线程停止存在。

Is something like the following possible in C on Linux platform: I have a thread say A reading system calls(intercepting system calls) made by application processes. For each process A creates a thread, which performs the required system call and then sleeps till A wakes it up with another system call which was made by its corresponding application process. When a process exits, it worker thread ceases to exist.

因此​​,它像一些converzing一个线程处理,然后扇出多个线程,每处理一个线程。

So its like a number of processes converzing on a thread which then fans out to many threads with one thread per process.

感谢

推荐答案

如果您正在寻找某种线程池的实施,并不严格限制在CI会推荐的线程池(这几乎是提升)。它易于使用,并且很瘦。你现在真正需要的逻辑是系统事件的捕获,然后生成一个新的任务线程将执行调用。线程池将保留所有创建的线程的跟踪和自动线程分配的工作。

If you are looking for some kind of threadpool implementation and are not strictly limited to C I would recommend threadpool (which is almost Boost). Its easy to use and quite lean. The only logic you now need is the catching of the system event and then spawn a new task thread that will execute the call. The threadpool will keep track of all created threads and assign work automatically to the threads.

修改

既然你只限于C,试试这个实施。它看起来相当完整的,相当简单,但它基本上都会做的工作。

Since you are limited to C, try this implementation. It looks fairly complete and rather simple, but it will basically do the job.

这篇关于许多过程由一个线程执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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