Questions tagged [test-and-set]
26 questions
1
vote
1 answer
History of the ++/-- Operators as compared to the test-and-set instruction/operation
I am taking CS420 - Operating Systems. My professor mentioned something in class the other day that peaked my interest and I have been researching it and have gotten close but cannot find out the answer.
He mentioned that him and another…

Michael Riley
- 67
- 1
- 10
1
vote
2 answers
Mixing lock-less and lock-full thread synchronization with atomic TestAndSet in C++
I have a consumer thread that must read from a buffer without locking. It is fine if the operation must be skipped because a producer thread is writing to the buffer. So, the most appropriate choice seems to me to be an atomic TestAndSet on some…

Dan
- 802
- 6
- 22
1
vote
1 answer
Why CompareAndSwap is more of a powerful instruction than TestAndSet?
Please consider the following piece of code for CompareAndSwap and let me know why this atomic instruction is more powerful than atomic TestAndSet for being a mutual exclusion primitive?
char CompareAndSwap(int *ptr, int old, int new) {
unsigned…

Mona Jalal
- 34,860
- 64
- 239
- 408
0
votes
1 answer
Should I use notify() instaed of notifyAll() in this case?
I was thinking about this code:
public class SharedVariable {
private T value;
public SharedVariable(T init){
this.value = init;
}
public synchronized void testAndSet(Predicate super T> p, T value)
throws…

Marsh
- 1
- 1
0
votes
1 answer
test_and_set makes the thread deadlock
#include
using namespace std;
int cnt=0;
int locked=0;
int test_and_set(int * lock){
int temp=*lock;
*lock=1;
return temp;
}
void cntOnes(int t){
while(test_and_set(&locked));
for(int i=0;i<2000;i++){
…

VEMBU KARTHICK T
- 29
- 2
0
votes
1 answer
TAS instruction 68000
To handle concurrency in an M68000 assembly program, I need to understand how the TAS instruction works.
I don't really care about the theoretical description that I can see from the manual (e.g. http://68k.hax.com/TAS). More than anything I would…

Luigi
- 181
- 3
- 15
0
votes
2 answers
Implementation of a lock using test and set
Below is the code is given in OSTEP book regarding the implementation of a lock using test and set instruction. My question is that in such implementation, couldn't a thread that is not holding the lock call the unlock function and take away the…

Aviral Verma
- 488
- 4
- 11
0
votes
4 answers
How to use TestAndSet() for solving the critical section problem?
I'm studying for an exam and I'm having difficulty with a concept. This is the pseudo code I am given:
int mutex = 0;
do {
while (TestAndSet(&mutex));
// critical section
mutiex = 0;
// remainder section
} while (TRUE);
My instructor says…

Dan Mantyla
- 1,840
- 1
- 22
- 33
0
votes
0 answers
Why can't TSL offer secure atomic operations for multiple threads
Why does using the atomic operating system's system call of TSL doesn't provide us with a thread safe solution for more than two simultaneous threads \ processes?
Edited: I'm sorry for the mistake, I meant TSL and not test-and-set.
Reference to wiki…

vondip
- 13,809
- 27
- 100
- 156
-1
votes
1 answer
CMPXCHG and critical section implementation
The CMPXCHG statement works as follows:
CMPXCHG (common, old, new):
int temp
temp <- common
if common = old then
common <- new
return temp
What is the simplest possible algorithm for implementing a
critical section,…

Vasile
- 801
- 2
- 13
- 31
-1
votes
2 answers
How would one code test and set behavior without a special hardware instruction?
Most of the implementations I find require a hardware instruction to do this. However I strongly doubt this is required (if it is, I can't figure out why...)

vlee
- 1,369
- 3
- 14
- 23