Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 904
  • Last Modified:

Explain Atomic Instructions and TSL test and set lock

does anyone knows a clear explanation about Atomic Instructions and TSL test and set lock, I mean theorical explanation of this two concepts that i can have a better understanding with what is going on

Thanks
0
jsctechy
Asked:
jsctechy
1 Solution
 
stumpy1Commented:
0
 
rdrunnerCommented:
Hello....

a short explantion of atomic is..."from the point of view of other transactions, it either happens completely or not at all."


So basically you are not allowed to do only "half" a transaction... Like Crediting my checking account but forgetting to deduct the money from your account.. Both actions need to happen. It cant be that you credit my account and then figure out you dont have the balance to transfer the money to my account and abort then. (I prefer this example since here only the bank looses money and i get a few bucks extra ;) )

0
 
jsctechyAuthor Commented:
thanks for that clear explanation about atomic that really make a bit of sense to me better than having tons of websites telling me source codes where i can follow what are they trying to achive. Now there is an easy explanation for TSL

Thanks for that comment

0
 
rdrunnerCommented:
Well

Atomic is only one part of a transaction. An transaction needs to follow the acronym "ACID" ACID stands for "atomicity, consistency, isolation, and durability"

The other words make sense i hope if not ask again :)=

0
 
darconeCommented:
TSL is a instruction (usually implemented on some CPU:s) that is used to implement the critical section problem (critical sections are used to implement atomic actions, in turn). What it does is, it sets a variable to the value you pass to it, and returns the old one you replaced - both atomically. TSL means Test and Set Lock. Imagine you have two threads that you want synchronized, meaning that you donĀ“t want a piece of code in both of them to be able to run at once:

Thread1 {

 int currentMoney = get amount of money in account...

...

 set account balance to currentMoney - spentMoney;
}

Thread2 {
 
 int currentMoney = get amount of money in account

...

 set account balance to currentMoney + earnedMoney;
}

Now imagine that Thread1 stops where the three dots are (...) and Thread2 runs, and completes. Then thread1 still has the OLD value of the account balance, and will update the balance to what it remembered, causing a nasty bug and either you or the bank will lose money without a trace.

What you do in a situation like this, is you encluse the important code in critical sections, making the critical sections totally atomic in regard to eachother. This is done using mutual exclusion and lock variables, this is where TSL is used. A CSEntry function could look like: (CSEntry = Critical section entry):

CSEntry(lockVar) {

 while(TSL(lockVar) == 1) sleep();
}

And equally simple, CSEntry:

CSEntry() {

 lockvar = 0;
}

Hope this helps, and good luck ;)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now