- Aug 12, 2014
- 522
- 3
- 81
Hey Guys,
I'm finishing a book right now on assembly for the x86. It focuses mostly on 32-bit systems but does touch upon some 64-bit programming.
Anyway, it's a large book and I only have 70 pages left to go. However, there has been no mention of threading whatsoever. Further, upon reviewing the contents, it doesn't look like threads will be mentioned in the last 70 pages either.
Are threads higher level software abstractions? Do they exist below the OS / compiler / HLL level at all?
Intel processors have something called hyper-threading. However, after a cursory Wikipedia review, it appears that hyper-threading is a way for a processor to execute code from two different processes within the same clock period, not two different threads from the same process.
I'm beginning to think that a processor has no notion of threading or any "instruction bundling" at all and just executes instructions as they come.
Am I correct?
If I am, is it possible to fake a multi-threaded execution?
Example:
Let's say I'm executing a process and at some point the process entails two sub-tasks that at the most granulated level, the level of assembly code, have nothing to do with each other.
Let's say sub-task 1's job is to put the string "Hello!" on the console 10 times, and sub-task 2's job is to add the members of an array.
Can I simulate a multi-threaded experience like this:
(pseudo assembly)
thread 1:
send "Hello!" to console
send "Hello!" to console
check thread 2's counter
jump to thread 2 if condition holds
unconditional jump to thread 1
thread 2:
add vector element i to accumulator
add vector element i+1 to accumulator
check thread 1's counter
jump to thread 1 if condition holds
unconditional jump to thread 2
I've essentially sort of faked a multi-threaded experience, haven't I?
Also, when you use a HLL to write multi-threaded code, when it's compiled, do you get something like what I've created?
Thanks.
I'm finishing a book right now on assembly for the x86. It focuses mostly on 32-bit systems but does touch upon some 64-bit programming.
Anyway, it's a large book and I only have 70 pages left to go. However, there has been no mention of threading whatsoever. Further, upon reviewing the contents, it doesn't look like threads will be mentioned in the last 70 pages either.
Are threads higher level software abstractions? Do they exist below the OS / compiler / HLL level at all?
Intel processors have something called hyper-threading. However, after a cursory Wikipedia review, it appears that hyper-threading is a way for a processor to execute code from two different processes within the same clock period, not two different threads from the same process.
I'm beginning to think that a processor has no notion of threading or any "instruction bundling" at all and just executes instructions as they come.
Am I correct?
If I am, is it possible to fake a multi-threaded execution?
Example:
Let's say I'm executing a process and at some point the process entails two sub-tasks that at the most granulated level, the level of assembly code, have nothing to do with each other.
Let's say sub-task 1's job is to put the string "Hello!" on the console 10 times, and sub-task 2's job is to add the members of an array.
Can I simulate a multi-threaded experience like this:
(pseudo assembly)
thread 1:
send "Hello!" to console
send "Hello!" to console
check thread 2's counter
jump to thread 2 if condition holds
unconditional jump to thread 1
thread 2:
add vector element i to accumulator
add vector element i+1 to accumulator
check thread 1's counter
jump to thread 1 if condition holds
unconditional jump to thread 2
I've essentially sort of faked a multi-threaded experience, haven't I?
Also, when you use a HLL to write multi-threaded code, when it's compiled, do you get something like what I've created?
Thanks.
Last edited: