11

I understand that a process a unit of resource ownership and executable instructions. Threads allow a process to share its resources with multiple executions, and it's easier for an OS to schedule threads because of all the overhead associated with whole processes.

But why the name thread? Does it have some reference to string or the interleaving of execution? Even so, this isn't an intuitive term in my opinion.

Matt
  • 399
  • 2
  • 12

7 Answers7

16

Have you looked in a dictionary? The word thread has a meaning past sewing.

3: something continuous or drawn out: as

a: a line of reasoning or train of thought that connects the parts in a sequence (as of ideas or events)

http://www.merriam-webster.com/dictionary/thread

GrandmasterB
  • 37,990
  • 7
  • 78
  • 131
  • Interesting. I had done a search for "define thread" but that definition was not one of them. I'm glad you mentioned this, because it's abstract enough to cross the bridge from general usage to programming. – Matt Jan 25 '14 at 01:59
10

Ever seen how multiples threads, twisted, form a thicker, stronger cord ?

That's the metaphor, every thread is independent but all threads together collaborate to a final computational output. Besides, as in the textile thread, a thread can break without compromising the structure of the whole cord.

enter image description here

Tulains Córdova
  • 39,201
  • 12
  • 97
  • 154
  • 2
    while I always pictured "threads" just you and GrandmasterB described them, not sure about the whole "twisted, thicker, stronger cord". Instead most threads in an OS look something like this: http://www.miqel.com/bonnaroo_2008_music/yarn_string_trips.jpg (guy on the right would be the memory controller) Yeah, some times few of those strings are intended to solve a common problem, but most are just there and OS just lets them all do whatever they want (within reason) – DXM Jan 24 '14 at 23:15
7

tl;dr: They're called threads because "thread" is an apt metaphor.


When you start a thread, you rely on the operating system to allocate processing time so that your thread can execute. While your thread is executing, the processor (or core) is placing all of its attention on your thread. When the operating system switches the core to a different thread, your thread stops executing while the other thread is being serviced.

So execution jumps around all over the place. But the integrity of the set of machine instructions remains intact, in spite of these jumps, because we build fences and concurrency mechanisms to protect its state, and the state of the objects it interacts with.

So the thread refers, not to the execution of instructions in any particular thread, but to the instructions that will eventually be executed within the thread that we have created. Each thread, in other words, can be thought of as an individual machine or agent (we call them lightweight processes), without having to think about all of the context switches that the operating system is performing to give the appearance that they're all executing simultaneously.

In other words, despite all of the jumping around that the OS does behind the scenes, that which we call a thread (the sequence of operations that we are executing in a lightweight process) still can be thought of as the same sequence of operations, had we not spawned the thread, assuming we have taken the necessary concurrency protections.


If this description seems too weighty and abstract, then think of a thread in a forum, like Reddit. You can branch off new discussions; each discussion is its own thread. You can jump back and forth between threads. But each thread still maintains its structural integrity as an individual conversation.

Robert Harvey
  • 198,589
  • 55
  • 464
  • 673
4

It is difficult to untangle (pun fully intended) the source of the term "Thread" because various things muddy the waters.

The usage of thread in the forum or email sense almost certainly stems from the phrase "thread of conversation" which according to this dates back as far as 1593.

Things seem to be less clear for the meaning of thread you are asking about though since according to this link, threads as we know them weren't actually called "threads" until the 70s or possibly early 80s despite the implementation of a shared memory process actually predating what we think of as heavyweight processes today. Given that a related form of shared memory multiprocessing is called a "fiber" I strongly suspect that the word "thread" is suppose be reminiscent of weaving cloth or some other textile-related analogy.

Evicatos
  • 662
  • 6
  • 12
3

I think it has to do with a 'thread of reasoning' or 'thread of thought'.

In contrast to a process, threads share memory. So if a process is likened with a person with his/her own mind (memory), a thread can be likened with one line of thought within that mind.

Alexander Torstling
  • 1,226
  • 1
  • 8
  • 12
1

I read somewhere the analogy of threads in programming.Think CPU as a sewing needle, and the thread as the actual string. Now, if you have multiple sewing needles but just a one thread. Don't you think, it will be quite inefficient. The other CPU/sewing needle will be waiting for the thread to be available. However, if we have multiple threads, then the job can be accomplished in a short time.

dexterous
  • 119
  • 4
-1

Maybe for the fact that the process is running in a thin circuit as electrical states, that are so thin to be called wire, so it's a thread

Dev
  • 1