Google 網路論壇不再支援新的 Usenet 貼文或訂閱項目,但過往內容仍可供查看。

thread vs process

瀏覽次數:130 次
跳到第一則未讀訊息

Marco Moock

未讀,
2024年1月18日 凌晨3:14:121月18日
收件者:
Hello!

Some programs say that they are multi-process or multi-threaded.

What is the exact difference here?

--
kind regards
Marco

Spam und Werbung bitte an ichwillges...@nirvana.admins.ws

Terje Mathisen

未讀,
2024年1月18日 凌晨4:29:221月18日
收件者:
Marco Moock wrote:
> Hello!
>
> Some programs say that they are multi-process or multi-threaded.
>
> What is the exact difference here?

Welcome to comp.arch where we really love this kind of homework questions!

The difference is of course mostly one of semantics only, where
multi-threaded means that each cpu follows a single thread of execution,
working independently, whereas multi-process has a bunch of cpus all
cooperating on a single task.

Terje


--
- <Terje.Mathisen at tmsw.no>
"almost all programming can be viewed as an exercise in caching"

Chris M. Thomasson

未讀,
2024年1月18日 下午4:09:531月18日
收件者:
On 1/18/2024 12:14 AM, Marco Moock wrote:
> Hello!
>
> Some programs say that they are multi-process or multi-threaded.
>
> What is the exact difference here?
>

What about multiple multi-threaded processes? ;^)

John Levine

未讀,
2024年1月18日 下午5:17:181月18日
收件者:
According to Chris M. Thomasson <chris.m.t...@gmail.com>:
You know perfectly well that's architecturally impossible. See the previous excellent answer.



--
Regards,
John Levine, jo...@taugh.com, Primary Perpetrator of "The Internet for Dummies",
Please consider the environment before reading this e-mail. https://jl.ly

Chris M. Thomasson

未讀,
2024年1月18日 下午5:28:091月18日
收件者:
On 1/18/2024 2:17 PM, John Levine wrote:
> According to Chris M. Thomasson <chris.m.t...@gmail.com>:
>> On 1/18/2024 12:14 AM, Marco Moock wrote:
>>> Hello!
>>>
>>> Some programs say that they are multi-process or multi-threaded.
>>>
>>> What is the exact difference here?
>
>> What about multiple multi-threaded processes? ;^)
>
> You know perfectly well that's architecturally impossible. See the previous excellent answer.
>
>
>

Multiple multi-threaded processes are impossible? Really? Since when...

Lawrence D'Oliveiro

未讀,
2024年1月18日 下午6:54:431月18日
收件者:
On Thu, 18 Jan 2024 10:29:17 +0100, Terje Mathisen wrote:

> The difference is of course mostly one of semantics only ...

As opposed to syntax, perhaps?

Lawrence D'Oliveiro

未讀,
2024年1月18日 下午6:58:001月18日
收件者:
On Thu, 18 Jan 2024 09:14:05 +0100, Marco Moock wrote:

> Some programs say that they are multi-process or multi-threaded.
>
> What is the exact difference here?

Think of a bare-minimum context of execution: a program counter that
points at an instruction stream, and some machine state for executing
those instructions.

Obviously that’s not enough to run any meaningful program: you also need
memory to hold that instruction stream and associated data, plus other OS
context like open files, network connections, access-control credentials
etc. Call that “process context”.

So if two execution contexts have their own process contexts, you call
them “separate processes”. If they share the same process context, you
call them “threads within a process”.

I think that’s about as basic a definition as you can get.

George Neuner

未讀,
2024年1月18日 晚上11:55:081月18日
收件者:
On Thu, 18 Jan 2024 14:28:03 -0800, "Chris M. Thomasson"
<chris.m.t...@gmail.com> wrote:

>On 1/18/2024 2:17 PM, John Levine wrote:
>> According to Chris M. Thomasson <chris.m.t...@gmail.com>:
>>
>>> What about multiple multi-threaded processes? ;^)
>>
>> You know perfectly well that's architecturally impossible. See the
>> previous excellent answer.
>
>Multiple multi-threaded processes are impossible? Really? Since when...

I think John may be assuming that a CPU/core runs only one thread at a
time ... which isn't necessarily true.

Chris M. Thomasson

未讀,
2024年1月19日 凌晨12:23:391月19日
收件者:
I wonder if I missed his main point?

Lawrence D'Oliveiro

未讀,
2024年1月19日 凌晨1:19:161月19日
收件者:
On Thu, 18 Jan 2024 23:55:01 -0500, George Neuner wrote:

> I think John may be assuming that a CPU/core runs only one thread at a
> time ... which isn't necessarily true.

Those “hardware threads” are probably best described as “virtual CPUs”.
They have nothing to do with threads versus processes in the software
sense. They are a way of sharing functional units to make it look almost,
but not quite, like separate CPUs.

Michael S

未讀,
2024年1月19日 上午9:10:121月19日
收件者:
On Thu, 18 Jan 2024 10:29:17 +0100
Terje Mathisen <terje.m...@tmsw.no> wrote:

> Marco Moock wrote:
> > Hello!
> >
> > Some programs say that they are multi-process or multi-threaded.
> >
> > What is the exact difference here?
>
> Welcome to comp.arch where we really love this kind of homework
> questions!
>
> The difference is of course mostly one of semantics only, where
> multi-threaded means that each cpu follows a single thread of
> execution, working independently, whereas multi-process has a bunch
> of cpus all cooperating on a single task.
>
> Terje
>
>

I am not sure about it.
IMHO, first and foremost it is a matter of what industry you are in.
The programs used in textile tend to be multi-threaded.
On the other hand, food industry is known to rely on multi-process
programming, sometimes detrimentally to their consumer's health.

George Neuner

未讀,
2024年1月19日 中午12:16:331月19日
收件者:
That's quite true. The point I was making was that multiple threads
of the same process can be running simultaneously even on the same
core.

George Neuner

未讀,
2024年1月19日 中午12:28:171月19日
收件者:
On Thu, 18 Jan 2024 21:23:33 -0800, "Chris M. Thomasson"
<chris.m.t...@gmail.com> wrote:

>On 1/18/2024 8:55 PM, George Neuner wrote:
>> On Thu, 18 Jan 2024 14:28:03 -0800, "Chris M. Thomasson"
>> <chris.m.t...@gmail.com> wrote:
>>
>>> On 1/18/2024 2:17 PM, John Levine wrote:
>>>> According to Chris M. Thomasson <chris.m.t...@gmail.com>:
>>>>
>>>>> What about multiple multi-threaded processes? ;^)
>>>>
>>>> You know perfectly well that's architecturally impossible. See the
>>>> previous excellent answer.
>>>
>>> Multiple multi-threaded processes are impossible? Really? Since when...
>>
>> I think John may be assuming that a CPU/core runs only one thread at a
>> time ... which isn't necessarily true.
>>
>
>I wonder if I missed his main point?

If so I missed it too. John seemed to refer to Terje's answer which
is about what (virtual) CPUs are doing in either case.

Terje's answer is correct but incomplete: it appears to imply that
multiple threads cannot be doing the same task, and that multiple
processes must be doing the same task. Neither necessarily is true.

BGB

未讀,
2024年1月19日 下午2:02:321月19日
收件者:
Though, another way to see it would be that:
Threads and processes can do whatever, and there need not be a hard
distinction.

Though, on most systems:
Threads run in the same address space;
Processes run in different address spaces, and typically represent
different programs.


Fun on a system where everything runs in one address space and the
distinction between threads and processes is a bit more ambiguous.


Lawrence D'Oliveiro

未讀,
2024年1月19日 下午3:24:451月19日
收件者:
On Fri, 19 Jan 2024 13:02:26 -0600, BGB wrote:

> Though, on most systems:
> Threads run in the same address space;
> Processes run in different address spaces, and typically represent
> different programs.

The usual way of saying it is threads are “shared-everything” and
processes are (nearly) “shared-nothing”, at least by default.

On a POSIX system, you create one of the former with pthread_create(3),
and one of the latter with fork(2). But on Linux, both of these are
basically wrappers around clone(2)
<https://manpages.debian.org/2/clone.2.html>. And by using that call
directly, you get some interesting options for creating entities that are
somewhat in-between.

Scott Lurndal

未讀,
2024年1月19日 下午3:49:111月19日
收件者:
SVR4.2ES/MP had two versions of fork.

fork(2) would only create a single thread in the forked process
forkall(2) would create a new process with all the same threads as the
parent process.

The latter never gained any traction and when POSIX.4 came along, wasn't
accepted by the standard working group.

Lawrence D'Oliveiro

未讀,
2024年1月19日 下午5:21:211月19日
收件者:
On Fri, 19 Jan 2024 20:49:06 GMT, Scott Lurndal wrote:

> SVR4.2ES/MP had two versions of fork.
>
> fork(2) would only create a single thread in the forked process
> forkall(2) would create a new process with all the same threads as the
> parent process.
>
> The latter never gained any traction and when POSIX.4 came along, wasn't
> accepted by the standard working group.

Big surprise ...

Did they try to explain what the point of it was?

Chris M. Thomasson

未讀,
2024年1月19日 下午5:32:531月19日
收件者:
On 1/19/2024 12:24 PM, Lawrence D'Oliveiro wrote:
> On Fri, 19 Jan 2024 13:02:26 -0600, BGB wrote:
>
>> Though, on most systems:
>> Threads run in the same address space;
>> Processes run in different address spaces, and typically represent
>> different programs.
>
> The usual way of saying it is threads are “shared-everything” and
> processes are (nearly) “shared-nothing”, at least by default.

Intraprocess communication is dealing with multiple threads of a single
process.

Interprocess communication is dealing with multiple processes.

A program can be comprised of multiple processes that have multiple
threads within them...

Interprocess communication can be interesting, for instance think along
the lines of robust mutexes.

Lock-free and wait-free sync algorithms can be used for both,
Intraprocess and/or Interprocess sync...

Scott Lurndal

未讀,
2024年1月19日 晚上7:22:231月19日
收件者:
Lawrence D'Oliveiro <l...@nz.invalid> writes:
I don't recall the details. There wasn't much experience
with unix threads at the time ('90ish), other than the
digital ultrix threads. It's probably in one of the ES/MP
design documents I have squirrelled aways somewhere.

MitchAlsup1

未讀,
2024年1月21日 下午4:45:431月21日
收件者:
Marco Moock wrote:

> Hello!

> Some programs say that they are multi-process or multi-threaded.

> What is the exact difference here?

To actually try an answer your question::

Multi-process is a system that allows for multiple independent processes to share
one or more CPUs.

Multi-threaded is a system that allows for multiple processes and allows some of
them to share memory while occupying one or more CPUs in a system.

In some theoretical senses: multi-threaded is multiple threads within a single
address space (PThreads,...); although I soften that hard edge and allow even
processes which share memory through mmap() to be considered multi-threaded.
0 則新訊息