I was watching this video about multithreading from Computerphile and at 10:03 it shows this:
where T1 and T2 are threads, and under them are machine instructions.
So, is a thread nothing but a sequence of machine instructions?
I was watching this video about multithreading from Computerphile and at 10:03 it shows this:
where T1 and T2 are threads, and under them are machine instructions.
So, is a thread nothing but a sequence of machine instructions?
Well, at the end of the day, everything that a processor executes is a machine instruction from its instruction set (at least at micro-architecture level of abstraction; if you want to go further at logic gate level then it's bits; if you want to go further at electronics level then it's voltages, etc.).
So yes, a thread is nothing but a sequence of machine instructions as you saw in that video.
While Noob_Guy's answer is correct, I want to add the following:
In the "olden days" a CPU could only do one task a time and it would bounce back and forth between tasks. Now with multi-core and multi-CPU systems, as well as proper programming support, multiple tasks - threads - can run simultaneously. This means more things can be done at once, without slowing down the CPU, as it waits for another task/thread to finish.
What's a thread? A thread is a list of instructions that is executed in serial. Each thread synchronously runs all the code, no code in a thread is mixed around. This means that every active thread just starts at the code on line 1, then line 2, line 3 and so forth. You can run multiple threads next to each other. Each thread should execute its code as fast as possible, but the CPU only has a limited amount of cores. Each core can only run one instruction at a time, the CPU thus switches between threads so they all progress at the same time (asynchronously).
What is the purpose of a thread? If we want to run different tasks "at the same time" we can launch multiple threads. For example when making an application that has a graphical interface. We want the program to do something that takes a couple minutes to complete. If we run all code on a single thread (the UI thread), our program will become unresponsive until that task has completed. Threads solve this. We can launch the task that takes a long time on a second thread and use the main thread to update a progress bar based on how far the second thread has gotten.
Conclusion: Threads don't exist physically, they are just ToDo-lists of what instructions need to be executed. Threads are indeed sequences of machine code. It's important to note that each thread runs their machine code in a fixed order. Multiple threads can run pieces of code next to each other.