Talk:Test-and-set

message: The article previously had a paragraph that said
"However, in multiprocessor systems, it is impossible and undesirable to disable interrupts on all processors at the same time; and even with interrupts disabled, two or more processors could be attempting to access the same semaphore's memory at the same time. The test-and-set instruction, allows any processor to atomically test and modify a memory location, preventing such multiple processor collisions. The processor should still disable its interrupts, as in a uniprocessor system, before executing a test-and-set, to prevent a deadlock if another process running on this processor also accesses that semaphore."
I'm pretty sure that last sentence is incorrect, so I deleted it. My understanding is that the test-and-set assembly language instruction cannot be interrupted by any interrupts, including the one that causes a test-switch to another thread running on this processor.
Please tell me if that last sentence was correct for any processor.
-- DavidCary 05:36, 3 May 2004 (UTC)
thread_title: Untitled

message: Compare 
 int TestAndSet(int* lockPtr) {
    int oldValue;
    oldValue = SwapAtomic(lockPtr, 1);
    return oldValue != 0;
 }
with
 #define LOCKED 1
 int TestAndSet(int* lockPtr) {
    int oldValue;
    oldValue = SwapAtomic(lockPtr, LOCKED); // returns value of first argument before swapping
    return oldValue == LOCKED;
 }
Result of test is no longer magic number. 
Creating union might be better for readability but is is not so commonly known ? 
People know what #define means more than what union means? 84.16.123.194 (talk) 18:13, 31 May 2009 (UTC)
thread_title:  Bad readability 

message: The last reference, http://people.cs.clemson.edu/~wayne/cpsc823/threads/testandset.s , appears to be 403ing. --130.85.224.228 (talk) 15:52, 13 March 2013 (UTC)
thread_title:  Broken reference 

message: This text: "Ultimately, IBM would release a processor family with 12 processors, whereas Amdahl would release a processor family with the architectural maximum of 16 processors" seems off-topic for this page, and certainly out-of-place in the Overview for the page.  I suggest we remove it. --Pnkfelix (talk) 13:56, 11 June 2013 (UTC)
thread_title:  Extraneous IBM vs Amdahl text in Overview 

message: What kind of instruction set it is? There's no TSL instruction in x86.
For 8086 that should be (taken from The Intel 8086 Microprocessor: A 16-bit Evolution of the 8080 by Morse et all):
  ENTER_REGION:
    MOV AL, 1            ; The intent to lock
    LOCK XCHG SEMA, AL   ; test and set lock
    TEST AL, AL          ; check if we've got the lock
    JNZ ENTER_REGION     ; retry if lock has been taken by someone else
  ...
    CRITICAL REGION
  ...
    MOV SEMA, 0          ; clear the lock when done  — Preceding unsigned comment added by Roolebo (talk • contribs) 19:29, 23 January 2019 (UTC)
replies: text: It's no particular instruction set. The TSL instruction is explained in comment beside it. Wikipedia is in the business of explaining the general concept, not in teaching coding (that's Wikibooks responsibility), or any specific architecture.  A didactic "TSL" mnemonic, for a generic Test and Set Lock instruction, is used in a number of textbooks, including Tannenbaum. -- Finlay McWalter··–·Talk 20:34, 23 January 2019 (UTC)
thread_title:  Assembly listing for critical section