Skip to content
/ tas-lock Public

Test-and-set Lock uses an atomic value for critical section execution, and is suitable for educational purposes only.

License

Notifications You must be signed in to change notification settings

javaf/tas-lock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Test-and-set Lock uses an atomic value for indicating that some thread has engaged the lock and is executing its critical section (CS).

Each thread that wants to enter CS tries to engage lock, and checks to see if it was the one who managed to engage it (with an atomic operation). This has no effect if it was already engaged. If it managed to engage it, it proceeds to its CS, otherwise it just retries.

Once the thread is done with CS, it simply disengages the lock.

As all thread repeatedly attempt to engage the lock for themselves, it leads a storm on the processor memory bus (since the atomic operation ignores the cache). Since bus traffic is always high, it makes it difficult for the lock holder to disengage his lock (due to traffic). Also this scheme does not provide first-come-first- served fairness. Hence, this type of lock is only suitable for educational purposes.

Course: Concurrent Data Structures, Monsoon 2020
Taught by: Prof. Govindarajulu Regeti

lock():
1. When thread wants to access critical
   section, it tries to engage lock, for
   itself, with an atomic operation. This
   has no effect if it was already engaged.
   If it managed to engage it, it proceeds
   to its CS.
2. If not, it retries again.
unlock():
1. When a thread is done with its critical
   section, it simply sets the "locked" state
   to false.

See TASLock.java for code, Main.java for test, and repl.it for output.

references

About

Test-and-set Lock uses an atomic value for critical section execution, and is suitable for educational purposes only.

Topics

Resources

License

Stars

Watchers

Forks

Languages