> So. Has anyone on this forum actually used the TBEGIN and TEND 
instructions
> in their code? I would appreciate knowing what / why they chose to do 
so.
> I'm just trying to understand the real purpose of these instructions on 
a
> PRACTICAL level. Yes, I've read up on "Transactional Memory" on the web.
> And how it allows "atomic updates". But I would like a real world 
example
> of why use this vs. the older "atomic" instructions (TSET, CS, CDS, PLO,
> etc).

The existing locking instructions are pretty straightforward when coding 
them directly, but things can get messy when using them in generic service 
routines or in macros.  For example:

- You're updating existing code and find that you need to call a 
macro/routine that obtains a lock that you already hold.  Now you need to 
either update the interface to indicate you already hold it (and update 
all existing callers of that interface) or duplicate the routine to create 
a "lock already held" version.

- You're updating a service routine and now you need to obtain a lock. But 
some existing callers already hold the lock and others don't.  Do you 
treat "already held" as an expected condition and possibly overlook a 
programming error?  Or do you update the interface to include an "I 
already hold the lock" flag and then update all existing callers to use 
the new interface?

- You may find that you need to hold lock B, after you've already held 
lock A.  But another routine gets lock B first and then gets lock A.  If 
you know about the other routine then you might be able to rework your 
logic to get the locks in the same order.  If you don't know about the 
other routine and they end up running at the same time, you could end up 
in a deadly embrace.

- You need to perform an atomic update in a routine that's enabled for 
interruptions.  Disabling/enabling can be expensive, but if you get 
interrupted in the middle of your update, other routines might see your 
updates as not-so-atomic.

This doesn't mean that transactions should always be used in place of 
locks.  But transactions can sometimes be very useful in writing cleaner, 
more straightforward code by not having to worry about recursive holds or 
hold sequences.

- mb

Reply via email to