Thread

Share

What is a Thread?

The term thread has two meanings in computers: a comment or reply thread on social media, and a program thread being processed by the CPU.

What is a Thread on Social Media?

A thread on social media is a series of posts that are in reply of the other. That is, if someone posts a post, and someone posts a reply, and someone else replies to that, and so on, that forms a "thread" of posts.

Threads only exist in social media that support replying to a post with another post, such as on Twitter, Bluesky, and Mastodon. The social media called Threads is probably named after this very concept.

Originally, the threads existed in online forums, where an user would make a post to discuss a topic that would be the start of a thread, and other users would post replies. On such forums, it was possible to refer to a previous used posted, and quote it, but there was no tree-shaped post hierarchy view as we commonly have today on platforms like Reddit and Imgur.

On Reddit, replies to a thread are called "comments," so the thread is a comment thread.

What is a CPU Thread?

A thread in an operating system is a single program that can be executed in parallel to other programs.

Originally, CPUs only had one processor (one core, i.e. single-core CPUs), so they could only execute one step of an algorithm at a time. Even then, graphical operating systems were able to "look like" they were running several programs simultaneously between the CPU would quickly switch from processing one program to processing another. This switching, or aloting only a fraction of CPU time per program, is also known as scheduling. With scheduling, the system is able to update the position of the mouse cursor, advance animations, and hide or show things, before updating what is shown on the screen, so from the human user's perspective, it looks like everything updated simultaneously. We call this sort of processing concurrent processing.

On a CPU that has two cores, it's possible for two algorithms to be run in parallel. The difference between concurrent and parallel processing is that concurrent processing is synchronous: one program only starts getting process after the CPU stops processing the previous program. With parallel processing, we can't be sure about that, which can create all sorts of problems.

In both cases, we're able to have "threads." A thread is just a program that CAN be executed in parallel. It can also be executed concurrently. Let's say you have a modern CPU which has 10 cores. That means you can have 10 different programs running in parallel. But typically you'll have something like 80 programs (also called "processes" or "tasks") running in your computer at the same time. If split evenly, that's 8 programs per core.

A single program (or "process") can be multi-threaded. When a program is multi-threaded, what that means is that it can request the operating system to run part of the program in a separate thread. A common usage of this is for loading files while responding to user interaction.

In a single-threaded program, if you try to open a very large file and then click on something, the program won't respond. That's because it can only do one thing at a time. Either it's loading the file, or it's responding to your clicks. In order to do both of these things at once, it needs to be programmed so that it has a built-in scheduler to load only a portion of the file spending only a little bit of time on this task before checking if you clicked on anything, which is extremely complicated, or it can just use a thread, which is much simpler.

The multi-threaded program would then just spawn a thread for loading files, and when the file loads, the thread is terminated. Both the main thread and the file-loading thread share the same memory, so things that one thread loads in memory become accessible for the other thread even after the thread is terminated..

Comments

Leave a Reply

Leave your thoughts! Required fields are marked *