Boost logo

Boost :

Subject: Re: [boost] [transact] code in sandbox
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2010-02-11 14:23:51


----- Original Message -----
From: <strasser_at_[hidden]>
To: "vicente.botet" <vicente.botet_at_[hidden]>
Cc: "Bob Walters" <bob.s.walters_at_[hidden]>; <boost_at_[hidden]>
Sent: Thursday, February 11, 2010 6:01 AM
Subject: Re: [transact] code in sandbox

>
> Zitat von "vicente.botet" <vicente.botet_at_[hidden]>:
>
>>>
>>> *** new syntax for transaction scopes:
>>> syntax changed from:
>>> atomic{
>>> ...
>>> }retry;
>>>
>>> to
>>>
>>> do atomic{
>>>
>>> }commit();
>>>
>>> I prefer that syntax because it resembles the do{}while(...) syntax.
>>> downside is that it conflicts with transaction::commit() if the user
>>> chooses to define BOOST_TRANSACT_COMMIT to "commit" (as is done above).
>>
>> Maybe we can preserv both and see how the user react.
>
> the user can easily create the old syntax using the existing macros:
>
> #define atomic do BOOST_TRANSACT_ATOMIC
> #define retry BOOST_TRANSACT_COMMIT()

Hi,

with your macro definitions

#define BOOST_TRANSACT_BASIC_ATOMIC(TXMGR) \
 { \
  try{ \
   boost::transact::basic_transaction<TXMGR> ___tx;

#define BOOST_TRANSACT_BASIC_COMMIT(TXMGR) \
   } \
   ___tx.commit_(); \
  }catch(boost::transact::isolation_exception &i){ \
   i.unwind<TXMGR>(); \
   continue; \
  } \
 }while(false);

the catch has no access to the transaction variable as it out of scope (already destructed).
Some times it is interesting to increase the priority of a transaction to avoid starvation. In this case we need to be able to access the transaction.

On Boost.STM we have developed some macros (see stm/branches/vbe/boost/stm/language_like.hpp) . Next follows the Transact adaptation of some of them.

#define BOOST_TRANSACT_BASIC_ATOMIC(TXMGR, TX)\
    for (boost::transact::basic_transaction<TXMGR> TX; \
            ! TX.committed() && TX.restart_if_not_inflight(); \
          TX.no_throw_commit()) try

#define BOOST_TRANSACT_BASIC_RETRY(TXMGR, TX) \
    catch (boost::transact::isolation_exception &i) {}

#define BOOST_TRANSACT_BASIC_BEFORE_RETRY(TXMGR, TX)
    catch (boost::transact::isolation_exception &i)

#define BOOST_TRANSACT_BASIC_RETHROW(TXMGR, TX, E) \
    catch (E&) {(TX).commit(); throw;}

#define BOOST_TRANSACT_BASIC_ABORT_ON_EXCEPTION(TXMGR, TX, E) \
    catch (E&) {(TX).force_to_abort();}

BTW, what unwind does? Could you explain the problem it intend to solve.

With these macros the user will be able to

// retry when an a isolation exception occurs

BOOST_TRANSACT_ATOMIC(_) {

} BOOST_TRANSACT_RETRY(_)

// increase the priority of the transaction before restart the transaction when an a isolation exception occurs

BOOST_TRANSACT_ATOMIC(_) {

} BOOST_TRANSACT_BEFORE_RETRY(_) {_.increase_priority(); }.

// or retry when an a isolation exception occurs and retrow the exception Ex
 
BOOST_TRANSACT_ATOMIC(_) {
...
} BOOST_TRANSACT_RETRY
BOOST_TRANSACT_RETHROW(_, Ex)

// or retry when an a isolation exception occurs and abort when the exception Ex occurs

BOOST_TRANSACT_ATOMIC(_) {
...
} BOOST_TRANSACT_RETRY
BOOST_TRANSACT_ABORTON_EXCEPTION(_, Ex)

There are a lot of other macros. I'll present all these and more as for example how to exit succesfully from a transaction block (return, break, continue or goto) at BoostCon.

Let me know if you want I add them to Boost.Transact; this could be my little contrinution to Boost.Transact for the moment.

Best,
Vicente


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk