Threads, programs and processes, what's the difference?

@cyclicalobsessive,
In the past several threads on python paths, mutexes, and such-like you have discussed various kinds of programming “things” like programs, processes, and threads and:

  1. In some cases, you appear to use the terms interchangeably, as if they’re synonyms for each other.

  2. In other cases, you specifically stamp your feet, insisting that they’re all different beasties.

OK, 'fess up.  What is it?

My guesses:

  1. Programs, processes, and threads are all different though they may share a common heritage.

  2. Definitions:

    • A program is a stand-alone module that can be used either by itself or with other things to accomplish a task.
      • A library is a special case of a program where, though it might not be uniquely executable by itself, it provides valuable services to the including program.
      • An “included” library becomes a local “instance” of the library file itself subsumed into the program, almost as if it had been cut-and-pasted into it. (bad use of words, but I don’t know how to express it better.)
    • A process is the system’s instance of a running program.
      • Processes can be spawned by executing a program, the operating system executing a program, (or a service which is a special case of a program), or by something else running a program, (for example, the program you just ran.)
    • A thread is a special kind of programmatic process where a program, in essence, does two, (or more), things at the same time.
      • Threads are owned by the process that spawned them.
         
  3. Scope:

    • Programs/Processes:

      • A program has it’s own process and the process has its own local scope.  Anything included on imported into the program is subsumed into the local scope.
         
    • Libraries:
      Libraries become a part of the local scope of what subsumes them.

      • However, (especially in the case of libraries made up of classes), the individual routines withing the library can have their own local sub-scope.
         
    • Threads:

      • Threads are “sub-processes” spawned by a particular process and share the processes local scope.  (i.e.  Anything owned by any part of the process is owned and accessible by all parts of the process, including its threads.)

      • It might be possible for a thread to create and maintain a locally local scope unique to that thread and not shared with any other members of the process.

1 Like

I have no idea what you are referring to.

EXECUTION:

  • Life is simple when there is only one program/script/process which is only one thread. (99.999% of GoPiGo users)

  • Life gets more complicated when there is only one process but that process has more than one thread.

  • And when threads are re-entrant, programmers go insane and academics wax poetic.

  • Even more complicated is when a “system” consists of more than one process.

Multi-threading is a huge topic. Multi-processing is a huge topic. Both are techniques for handling asynchronous computing. They share some concepts but implement them differently.

Good you are thinking about it.

2 Likes

Each of these things that include a class(es)

This adds an entirely separate layer of scoping restrictions.

Assumption:

  • Anything inside a class, wherever it is instantiated, remains local to the class regardless of any other scoping rules.

Question

Program “a” creates a file: /[path]/“X”
Program a instantiates class “foo”
Class “foo” tries to create a file using the same file and path.

Program a spawns two processes a’ and a"
Each thread tries to create the same file.

Who owns the file?
Who’s on first?

1 Like

So, how close to reality are they?  Or am I still breathing too many paint fumes from the bodywork I’m doing on my car?

1 Like

The user that created the file “owns” from an user/group/world view.

Scope/ownership/access/privileges are each different concepts with overlapping participation in all this.

2 Likes

Sorry - can’t go there.

2 Likes

???

I was hoping for some feedback on how well I was understanding this.  (i.e. Are my assumptions correct and if not, how are they mistaken?)

1 Like

Really Jim - I am stretching to help you with the mutex thing.

Program: some code
Process: code being executed
Thread: code being executed within the process scope (Process is the first thread btw)

There are youtubes galore on operating systems, multi-processing, multi-threading, scope, access controls - I’m sorry.

1 Like

. . . .forgive me for not trusting 99% of the stuff I hear on YouTube.  My experience is that 90% of the content is by punters and the rest are wannabees - with a very, very small fraction of them being worth watching.

Mostly, when I’m on YouTube I expect to be entertained, not educated.  You, on the other hand, have actually been down in the trenches and have the scars on your knuckles typical of someone who has a clue.

However, I’ll give it a try.

1 Like