2
$\begingroup$

I have benn wondering about the following possibility: if I have multiple hardware threads on the same core, and then someone decides to use shared register to allow fast synchronization among threads that run on the CPU, and implements test-and-set on the register instead of doing it in main memory. Will this work? and if it works, why?

$\endgroup$
2
$\begingroup$

Synchronization based on test-and-set requires a shared data storage location that all the involved threads can read and modify. Your shared register is a shared data storage location.

The reason synchronizing on a register when the threads are running on different CPUs is that the register would not be shared (not be visible) to one of the threads. You should think of registers as memory locations with some features removed to make them faster.

In fact, something similar to your scenario was possible on SPARC processors. The SPARC had a large register file (something like 64 or 128 registers) with 8 registers that were always visible and then 24 register "windows" into the rest of the register file. Usually these windows were used to implement fast stack frames, but there were several experimental runtime systems that used the windows to support multiple threads.

$\endgroup$
  • $\begingroup$ oh tanks, but can we implement test-and-set operation on registers? and the number of threads that can run on the same core will be restricted few? and why? $\endgroup$ – Optimistic Apr 7 '15 at 13:18
  • $\begingroup$ 1. Yes. 2. Huh? 3. Why what? $\endgroup$ – Wandering Logic Apr 7 '15 at 13:20
  • $\begingroup$ how we can implement test-and-set operation on registers? 2- I mean the scenario above will run a few threads on the same core? it will restricted the number of threads or not? $\endgroup$ – Optimistic Apr 7 '15 at 13:28
  • $\begingroup$ I still don't get what you are asking. You implement test-and-set on a register by implementing an instruction that atomically copies the contents of register A to register B, and puts the value "1" in register A. $\endgroup$ – Wandering Logic Apr 7 '15 at 13:40
  • $\begingroup$ I don't know what you think will restrict the number of threads. If you've allocated a register to be visible to all threads running on that CPU, then it doesn't matter how many threads could be run, they can all access the register. $\endgroup$ – Wandering Logic Apr 7 '15 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.