子线程内的多处理 [英] Multiprocessing inside a child thread

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

问题描述

我正在学习有关多处理和多线程的知识.

I was learning about multi-processing and multi-threading.

据我了解,线程运行在同一个内核上,所以我想知道如果我在子线程内创建多个进程,它们是否也将限于该单个内核吗?

From what I understand, threads run on the same core, so I was wondering if I create multiple processes inside a child thread will they be limited to that single core too?

我正在使用python,所以这是关于该特定语言的问题,但是我想知道与其他语言是否相同?

I'm using python, so this is a question about that specific language but I would like to know if it is the same thing with other languages?

推荐答案

我不是pyhton专家,但我希望这与其他语言一样,因为它通常是OS的功能.

I'm not a pyhton expert but I expect this is like in other languages, because it's an OS feature in general.

一个进程由OS执行,并拥有一个将要执行的线程.这通常是您的程序.您可以在进程内部启动更多线程以进行大量计算或您必须执行的任何操作. 但是它们属于该过程.

A process is executed by the OS and owns one thread which will be executed. This is in general your programm. You can start more threads inside your process to do some heavy calculations or whatever you have to do. But they belong to the process.

一个或多个线程归一个进程所有,执行将分布在所有内核中.

One or more threads are owned by a process and execution will be distributed across all cores.

创建给定数量的线程时,通常应将这些线程分布在所有内核中.他们不仅限于执行phyton解释器的核心人员. 即使您从phyton代码创建子流程,该流程也可以并且应该在其他内核上运行.

When you create a given number of threads these threads should in general be distributed across all your cores. They're not limited to the core who's executing the phyton interpreter. Even when you create a subprocess from your phyton code the process can and should run on other cores.

您可以在此处阅读有关gernal概念的更多信息: 抢先式多任务处理

You can read more about the gernal concept here: Preemptive multitasking

有些使用不同语言的库将线程抽象到通常称为任务"或其他内容的线程. 对于这些特殊情况,它们可能仅在创建它们的线程中运行. 例如.在DotNet世界中,有一个线程和一个任务.人们在谈论任务时常常会误用线程"一词,通常该任务在创建该任务的线程中运行.

There're some libraries in different languages who abstract a thread to something often called a Task or something else. For these special cases it's possible that they're just running inside the thread they were created in. For example. In the DotNet world there's a Thread and a Task. Often people are misusing the term thread when they're talking about a Task, which in general runns inside the thread it was created.

这篇关于子线程内的多处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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