Changeset 14496 for docs/Perl6/Spec

Show
Ignore:
Timestamp:
10/24/06 17:20:23 (2 years ago)
Author:
audreyt
svk:copy_cache_prev:
21659
Message:

* Perl6::Spec::Concurrency: Update nomenclature.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • docs/Perl6/Spec/Concurrency.pod

    r12127 r14496  
    103103the BEGIN TRANSACTION was executed. 
    104104 
    105 Perl 6 supports this concept through Code blocks which are marked "is atomic". 
     105Perl 6 supports this concept through C<contend> blocks. 
     106 
    106107These sections are guaranteed to either be completed totally (when the Code 
    107108block is exited), or have their state reverted to the state at the start of 
    108 the Code block (with the L<retry> statement). 
     109the Code block (with the L<defer> statement). 
    109110 
    110111(EM: maybe point out if / how old style locks can be "simulated", for those 
     
    114115 
    115116    my ($x, $y); 
    116     sub c is atomic { 
     117    sub c { contend { 
    117118        $x -= 3; 
    118119        $y += 3; 
    119         if $x < 10 { retry } 
    120     }; 
    121  
    122     $e = &c.retry_with( &d ); #  
    123     $e(); 
    124  
    125     if $i { is atomic; ...  } else { ...; } 
    126  
    127 A Code block can be marked as "is atomic".  This means that code executed 
     120        if $x < 10 { defer } 
     121    } }; 
     122 
     123    maybe { c() } maybe { d() }; 
     124 
     125    if $i { contend { ...}  } else { ...; } 
     126 
     127A Code block can be prefixed with C<contend>.  This means that code executed 
    128128inside that scope is guaranteed not to be interrupted in any way. 
    129129 
    130 The start of a block marked "is atomic" also becomes a "checkpoint" to 
     130The start of a block marked C<contend> also becomes a I<checkpoint> to 
    131131which execution can return (in exactly the same state) if a problem occurs 
    132 (a.k.a. a L<retry> is done) inside the scope of the Code block. 
    133  
    134 =head3 retry 
    135  
    136 The C<retry> function basically restores the state of the thread at the 
     132(a.k.a. a L<defer> is done) inside the scope of the Code block. 
     133 
     134=head3 defer 
     135 
     136The C<defer> function basically restores the state of the thread at the 
    137137last checkpoint and will wait there until an external event allows it to 
    138 potentially run that atomic section of code again without having to retry 
    139 again. 
     138potentially run that atomic C<contend> section of code again without having 
     139to defer again. 
    140140 
    141141If there are no external events possible that could restart execution, an 
    142142exception will be raised. 
    143143 
    144 The last checkpoint is either the last atomic / non-atomic boundary, or 
    145 the most immediate caller constructed with C<retry_with>. 
    146  
    147 =head3 retry_with 
    148  
    149 The C<retry_with> method on an atomic Code object causes a checkpoint to 
    150 be made for C<retry>, creating an alternate execution path to be followed 
    151 when a C<retry> is done. 
     144The last checkpoint is either the outermose C<contend> boundary, or 
     145the most immediate caller constructed with C<maybe>. 
     146 
     147=head3 maybe 
     148 
     149The C<maybe> statement causes a checkpoint to be made for C<defer> for 
     150each block in the C<maybe> chain, creating an alternate execution path to 
     151be followed when a C<defer> is done.  For example: 
     152 
     153    maybe { 
     154        ... 
     155        some_condition() or defer; 
     156        ... 
     157    } maybe { 
     158        ... 
     159        some_other_condition() or defer; 
     160        ... 
     161    } maybe { 
     162        ... 
     163    } 
     164 
     165If placed outside a C<contend> block, the C<maybe> statement creates its 
     166own C<contend> barrier. 
    152167 
    153168=head3 limitations 
     
    180195A Code block marked "is critical" can not be interrupted in any way.  But 
    181196since it is able to access non-revertible data structures (such as 
    182 non-seekable file handles), it cannot do a C<retry> as it would be impossible 
     197non-seekable file handles), it cannot do a C<defer> as it would be impossible 
    183198to restore the state to the beginning of the Code block. 
    184199 
     
    294309        # if the counter with the "key" equals or exceeds a closure's limit, 
    295310        # the closure can't be entered until it's released 
    296         # (this can be trivially implmented using atomic+retry) 
     311        # (this can be trivially implmented using contend+defer) 
    297312    } 
    298313 
     
    328343{ 
    329344 
    330     is atomic;   # retry/orelse/whatever other rollback stuff 
     345    is atomic;   # contend/maybe/whatever other rollback stuff 
    331346                 # limitation: no external IO (without lethal warnings anyway) 
    332347                 # can't do anything irreversible