I have to have a way to have four threads run from a certain point at roughly the same time. For example
thread 1 : mov eax,ebx, mov ecx, edx, [S], mov eax, edx, ...
thread 2: sbb eax,ebx, [S], mov ecx, edx, ...
thread 3: mov eax,ebx, xchg eax,ebx, cmp edx, ecx, [S], mov eax, ebx, ...
thread 4: dec eax, sub eax,ecx, [S], ....
[S] is a place holder for a 'synchronization point'. After all threads have reached this point, they should start roughly at the same time. How do I do this?
The code I have is something like
number_of_threads 4
temp:
dd 0 ;a 'synchronization variable'
THREAD 1 code
;synchronization [S]
lock add [temp],0x1
wloop1:
cmp [temp], number_of_threads
jne wloop1
THREAD 2 code
;synchronization [S]
lock add [temp],0x1
wloop2:
cmp [temp], number_of_threads
jne wloop2
THREAD 3 code
;synchronization [S]
lock add [temp],0x1
wloop3:
cmp [temp], number_of_threads
jne wloop3
THREAD 4 code
;synchronization [S]
lock add [temp],0x1
wloop4:
cmp [temp], number_of_threads
jne wloop4
This way we make sure that all threads reach [S] and start off from there at roughly the same time. The code that follows [S] executes only if temp becomes number_of_threads Is there a problem with this code such as race? I am not even sure if this is the way to do this.