Changeset 35096 in project


Ignore:
Timestamp:
01/31/18 01:26:03 (3 weeks ago)
Author:
kon
Message:

rel 2.2.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/4/synch

    r34226 r35096  
    1212=== Critical Regions
    1313
    14 Where {{MUTEXFORM}} below the following forms are accepted:
    15 
    16 ; {{MUTEX}} : just a mutex
    17 ; {{(MUTEX [(LOCK-ARG ...) [(UNLOCK-ARG ...)]])}} : mutex with optional lock and unlock arguments
     14Where {{MUTEX-FORM}} below the following forms are accepted:
     15
     16; {{MUTEX-OBJECT}} : mutex
     17; {{(MUTEX-OBJECT [(LOCK-ARG...) [(UNLOCK-ARG...)]])}} : mutex w/ optional lock and unlock arguments
    1818
    1919==== Synchronized Invocation - Continuation Safe
     
    2323===== synch
    2424
    25 <macro>(synch MUTEXFORM [BODY ...]) => OBJECT</macro>
     25<macro>(synch MUTEX-FORM [BODY ...]) => object</macro>
    2626
    2727Execute {{BODY ...}} while {{MUTEX}} locked.
     
    3131===== synch-with
    3232
    33 <macro>(synch-with MUTEXFORM VARIABLE [BODY ...]) => OBJECT</macro>
     33<macro>(synch-with MUTEX-FORM VARIABLE [BODY ...]) => object</macro>
    3434
    3535Execute {{BODY ...}} while {{MUTEX}} locked and the mutex-specific of {{MUTEX}}
     
    3838Returns the result of {{BODY ...}}.
    3939
    40 ===== call/synch
    41 
    42 <macro>(call/synch MUTEXFORM PROCEDURE [ARGUMENTS ...]) => OBJECT</macro>
     40===== call-synch
     41
     42<macro>(call-synch MUTEX-FORM PROCEDURE [ARGUMENTS ...]) => object</macro>
    4343
    4444Invoke {{PROCEDURE}} on the argument list {{ARGUMENTS ...}} while {{MUTEX}}
     
    4747Returns the result of the {{PROCEDURE}} invocation.
    4848
    49 ===== call-with/synch
    50 
    51 <macro>(call-with/synch MUTEXFORM PROCEDURE [ARGUMENTS ...]) => OBJECT</macro>
     49===== call-synch-with
     50
     51<macro>(call-synch-with MUTEX-FORM PROCEDURE [ARGUMENTS ...]) => object</macro>
    5252
    5353Invoke {{PROCEDURE}} on the mutex-specific of {{MUTEX}}
     
    5656Returns the result of the {{PROCEDURE}} invocation.
    5757
    58 ===== apply/synch
    59 
    60 <macro>(apply/synch MUTEXFORM PROCEDURE [ARGUMENTS ...]) => OBJECT</macro>
     58===== apply-synch
     59
     60<macro>(apply-synch MUTEX-FORM PROCEDURE [ARGUMENTS ...]) => object</macro>
    6161
    6262Apply {{PROCEDURE}} to the argument list {{ARGUMENTS ...}} while {{MUTEX}}
     
    6565Returns the result of the {{PROCEDURE}} application.
    6666
    67 ===== apply-with/synch
    68 
    69 <macro>(apply-with/synch MUTEXFORM PROCEDURE [ARGUMENTS ...]) => OBJECT</macro>
     67===== apply-synch-with
     68
     69<macro>(apply-synch-with MUTEX-FORM PROCEDURE [ARGUMENTS ...]) => object</macro>
    7070
    7171Apply {{PROCEDURE}} to the mutex-specific of {{MUTEX}}) and the {{ARGUMENTS ...}}
     
    7474Returns the result of the {{PROCEDURE}} application.
    7575
    76 ===== synch/lock
    77 
    78 <macro>(synch/lock MUTEXFORM [BODY ...]) => OBJECT</macro>
     76===== synch-lock
     77
     78<macro>(synch-lock MUTEX-FORM [BODY ...]) => object</macro>
    7979
    8080Execute {{BODY ...}} while {{MUTEX}} locked, and leave mutex locked.
     
    8282Returns the result of {{BODY ...}}.
    8383
    84 ===== synch/unlock
    85 
    86 <macro>(synch/unlock MUTEXFORM [BODY ...]) => OBJECT</macro>
     84===== synch-unlock
     85
     86<macro>(synch-unlock MUTEX-FORM [BODY ...]) => object</macro>
    8787
    8888Execute {{BODY ...}} while {{MUTEX}} locked, and leave mutex unlocked.
     
    9393executing the {{BODY}}.
    9494
    95 ===== let/synch
    96 
    97 <macro>(let/synch BINDINGS [BODY ...]) => OBJECT</macro>
    98 
    99 {{BINDINGS}} is a list of {{(VARIABLE MUTEXFORM)}}.
    100 
    101 Expands into a nested {{(synch-with MUTEXFORM VARIABLE ...}} form, a '''{{synch-with}}'''
     95===== let-synch-with
     96
     97<macro>(let-synch-with BINDINGS [BODY ...]) => object</macro>
     98
     99{{BINDINGS}} is a list of {{(VARIABLE MUTEX-FORM)}}.
     100
     101Expands into a nested {{(synch-with MUTEX-FORM VARIABLE ...}} form, a '''{{synch-with}}'''
    102102for each binding pair in {{BINDINGS}}. The leftmost binding pair is the
    103103outermost.
     
    105105Returns the result of {{BODY ...}}.
    106106
    107 ===== set!/synch
    108 
    109 <macro>(set!/synch (VARIABLE MUTEXFORM) [BODY ...]) => OBJECT</macro>
     107===== set!-synch-with
     108
     109<macro>(set!-synch-with MUTEX-FORM VARIABLE [BODY ...]) => object</macro>
    110110
    111111While the {{MUTEX}} is locked, evaluates {{BODY ...}} with the {{VARIABLE}}
     
    115115Returns the new mutex-specific of {{MUTEX}}.
    116116
    117 ===== object/synch
    118 
    119 <macro>(object/synch MUTEXFORM [BODY ...]) => OBJECT</macro>
     117===== object-synch-cut-with
     118
     119<macro>(object-synch-cut-with MUTEX-FORM [BODY ...]) => object<-macro>
    120120
    121121Execute {{BODY ...}} while {{MUTEX}} locked.
     
    126126Returns the result of {{BODY ...}}.
    127127
    128 ===== record/synch
    129 
    130 <macro>(record/synch RECORD-SYMBOL RECORD-OBJECT [BODY ...]) => OBJECT</macro>
     128===== record-synch
     129
     130<macro>(record-synch RECORD-OBJECT RECORD-SYMBOL [BODY ...]) => object</macro>
    131131
    132132Execute {{BODY ...}} while the {{RECORD-OBJECT}} mutex is locked. The mutex is
     
    145145(define f1 (make-foo 1 2 (make-mutex 'foo)))
    146146
    147 (record/synch foo f1 (+ (foo-a f1) (foo-b f1)))
    148 </enscript>
    149 
    150 ===== record-synch/lock
    151 
    152 <macro>(record-synch/lock RECORD-SYMBOL RECORD-OBJECT [BODY ...]) => OBJECT</macro>
     147(record-synch foo f1 (+ (foo-a f1) (foo-b f1)))
     148</enscript>
     149
     150===== record-synch-lock
     151
     152<macro>(record-synch-lock RECORD-OBJECT RECORD-SYMBOL [BODY ...]) => object</macro>
    153153
    154154Execute {{BODY ...}} while the {{RECORD-OBJECT}} mutex is locked, and leave the
     
    157157Returns the result of {{BODY ...}}.
    158158
    159 {{RECORD-SYMBOL}} and {{RECORD-OBJECT}} are per '''{{record/synch}}'''.
    160 
    161 ===== record-synch/unlock
    162 
    163 <macro>(record-synch/unlock RECORD-SYMBOL RECORD-OBJECT [BODY ...]) => OBJECT</macro>
     159{{RECORD-SYMBOL}} and {{RECORD-OBJECT}} are per '''{{record-synch}}'''.
     160
     161===== record-synch-unlock
     162
     163<macro>(record-synch-unlock RECORD-OBJECT RECORD-SYMBOL [BODY ...]) => object</macro>
    164164
    165165Execute {{BODY ...}} while the {{RECORD-OBJECT}} mutex is locked, and leave the
     
    168168Returns the result of {{BODY ...}}.
    169169
    170 {{RECORD-SYMBOL}} and {{RECORD-OBJECT}} are per '''{{record/synch}}'''.
     170{{RECORD-SYMBOL}} and {{RECORD-OBJECT}} are per '''{{record-synch}}'''.
    171171
    172172Should the mutex be unlocked a warning is issued and the mutex is locked before
     
    178178otherwise the same behavior.
    179179
    180 ===== %call/synch
    181 
    182 <macro>(%call/synch MUTEXFORM PROCEDURE [ARGUMENTS ...]) => OBJECT</macro>
    183 
    184 ===== %call-with/synch
    185 
    186 <macro>(%call-with/synch MUTEXFORM PROCEDURE [ARGUMENTS ...]) => OBJECT</macro>
    187 
    188 ===== %apply/synch
    189 
    190 <macro>(%apply/synch MUTEXFORM PROCEDURE [ARGUMENTS ...]) => OBJECT</macro>
    191 
    192 ===== %apply-with/synch
    193 
    194 <macro>(%apply-with/synch MUTEXFORM PROCEDURE [ARGUMENTS ...]) => OBJECT</macro>
     180===== %call-synch
     181
     182<macro>(%call-synch MUTEX-FORM PROCEDURE [ARGUMENTS ...]) => object</macro>
     183
     184===== %call-synch-with
     185
     186<macro>(%call-synch-with MUTEX-FORM PROCEDURE [ARGUMENTS ...]) => object</macro>
     187
     188===== %apply-synch
     189
     190<macro>(%apply-synch MUTEX-FORM PROCEDURE [ARGUMENTS ...]) => object</macro>
     191
     192===== %apply-synch-with
     193
     194<macro>(%apply-synch-with MUTEX-FORM PROCEDURE [ARGUMENTS ...]) => object</macro>
    195195
    196196===== %synch
    197197
    198 <macro>(%synch MUTEXFORM [BODY ...]) => OBJECT</macro>
     198<macro>(%synch MUTEX-FORM [BODY ...]) => object</macro>
    199199
    200200===== %synch-with
    201201
    202 <macro>(%synch-with MUTEXFORM VARIABLE [BODY ...]) => OBJECT</macro>
    203 
    204 ===== %synch/lock
    205 
    206 <macro>(%synch/lock MUTEXFORM [BODY ...]) => OBJECT</macro>
    207 
    208 ===== %synch/unlock
    209 
    210 <macro>(%synch/unlock MUTEXFORM [BODY ...]) => OBJECT</macro>
    211 
    212 ===== %let/synch
    213 
    214 <macro>(%let/synch BINDINGS [BODY ...]) => OBJECT</macro>
    215 
    216 ===== %set!/synch
    217 
    218 <macro>(%set!/synch (VARIABLE MUTEXFORM) [BODY ...]) => OBJECT</macro>
    219 
    220 ===== %object/synch
    221 
    222 <macro>(%object/synch MUTEXFORM [BODY ...]) => OBJECT</macro>
    223 
    224 ===== %record/synch
    225 
    226 <macro>(%record/synch RECORD-SYMBOL RECORD-OBJECT [BODY ...]) => OBJECT</macro>
    227 
    228 ===== %record-synch/lock
    229 
    230 <macro>(%record-synch/lock RECORD-SYMBOL RECORD-OBJECT [BODY ...]) => OBJECT</macro>
    231 
    232 ===== %record-synch/unlock
    233 
    234 <macro>(%record-synch/unlock RECORD-SYMBOL RECORD-OBJECT [BODY ...]) => OBJECT</macro>
     202<macro>(%synch-with MUTEX-FORM VARIABLE [BODY ...]) => object</macro>
     203
     204===== %synch-lock
     205
     206<macro>(%synch-lock MUTEX-FORM [BODY ...]) => object</macro>
     207
     208===== %synch-unlock
     209
     210<macro>(%synch-unlock MUTEX-FORM [BODY ...]) => object</macro>
     211
     212===== %let-synch
     213
     214<macro>(%let-synch BINDINGS [BODY ...]) => object</macro>
     215
     216===== %set!-synch-with
     217
     218<macro>(%set!-synch-with MUTEX-FORM VARIABLE [BODY ...]) => object</macro>
     219
     220===== %object-synch-cut-with
     221
     222<macro>(%object-synch-cut-with MUTEX-FORM [BODY ...]) => object</macro>
     223
     224===== %record-synch
     225
     226<macro>(%record-synch RECORD-OBJECT RECORD-SYMBOL [BODY ...]) => object</macro>
     227
     228===== %record-synch-lock
     229
     230<macro>(%record-synch-lock RECORD-OBJECT RECORD-SYMBOL [BODY ...]) => object</macro>
     231
     232===== %record-synch-unlock
     233
     234<macro>(%record-synch-unlock RECORD-OBJECT RECORD-SYMBOL [BODY ...]) => object</macro>
    235235
    236236
    237237=== Object Synchronization
    238238
    239 ==== make-object/synch
    240 
    241 <procedure>(make-object/synch OBJECT [NAME]) => MUTEX</procedure>
     239==== make-synch-with-object
     240
     241<procedure>(make-synch-with-object OBJECT [NAME]) => mutex</procedure>
    242242
    243243Returns a mutex with a mutex-specific value of {{OBJECT}}, and optional mutex
     
    251251provided.
    252252
    253 ==== object?/synch
    254 
    255 <procedure>(object?/synch OBJECT [PREDICATE]) => BOOLEAN</procedure>
     253==== synch-with-object?
     254
     255<procedure>(synch-with-object? OBJECT [PREDICATE]) => bool</procedure>
    256256
    257257Is the {{OBJECT}} a synchronized object - a mutex with a non-void mutex
     
    261261binding. Otherwise any object is accepted.
    262262
    263 ==== define-constructor/synch
    264 
    265 <macro>(define-constructor/synch CTORNAME [ID])</macro>
    266 
    267 <enscript language=scheme>
    268 (define-constructor/synch make-hash-table hash-table/synch:)
     263==== define-constructor-synch
     264
     265<macro>(define-constructor-synch CTORNAME [ID])</macro>
     266
     267<enscript language=scheme>
     268(define-constructor-synch make-hash-table hash-table-synch)
    269269;=> similar
    270 (define (make-hash-table/sync . args)
    271   (make-object/synch (apply make-hash-table args) '(hash-table/synch:)) )
    272 </enscript>
    273 
    274 ==== define-predicate/synch
    275 
    276 <macro>(define-predicate/synch PREDNAME)</macro>
    277 
    278 <enscript language=scheme>
    279 (define-predicate/synch hash-table?)
     270(define (make-hash-table-sync . args)
     271  (make-synch-with-object (apply make-hash-table args) '(hash-table-synch)) )
     272</enscript>
     273
     274==== define-predicate-synch
     275
     276<macro>(define-predicate-synch PREDNAME)</macro>
     277
     278<enscript language=scheme>
     279(define-predicate-synch hash-table?)
    280280;=> similar
    281 (define (hash-table?/sync obj) (object?/synch obj hash-table?))
    282 </enscript>
    283 
    284 ==== define-operation/synch
    285 
    286 <macro>(define-operation/synch OPERNAME)</macro>
     281(define (hash-table?-sync obj) (synch-with-object? obj hash-table?))
     282</enscript>
     283
     284==== define-operation-synch
     285
     286<macro>(define-operation-synch OPERNAME)</macro>
    287287
    288288Note that the operand must be the first argument of {{OPERNAME}}.
    289289
    290290<enscript language=scheme>
    291 (define-operation/synch hash-table-set!)
     291(define-operation-synch hash-table-set!)
    292292;=> similar
    293 (define (hash-table-set!/sync mtx+obj . args)
     293(define (hash-table-set!-sync mtx+obj . args)
    294294  (let ((mtx (if (pair? mtx+obj) (car mtx+obj) mtx+obj)))
    295     (check-mutex+object 'hash-table-set!/synch mtx 'object/synch)
     295    (check-mutex+object 'hash-table-set!-synch mtx 'object-synch)
    296296    (synch-with mtx+obj obj (apply hash-table-set! obj args)) ) )
    297297</enscript>
     
    313313
    314314
    315 == Examples
    316 
    317 
    318315== Notes
    319316
    320 Inspired by Thomas Chust.
    321 
    322 
    323 == Bugs and Limitations
     317* Inspired by Thomas Chust.
     318
     319
     320== Bugs & Limitations
     321
     322* {{define-*-synch}} is obtuse.
    324323
    325324
     
    337336== Version history
    338337
     338; 2.2.0 : Deprecate {{../synch}} bindings. Add 'format-synch.scm'.
    339339; 2.1.4 : .
    340340; 2.1.3 : .
     
    347347== License
    348348
    349 Copyright (C) 2009-2017 Kon Lovett.  All rights reserved.
     349Copyright (C) 2009-2018 Kon Lovett.  All rights reserved.
    350350
    351351Permission is hereby granted, free of charge, to any person obtaining a
Note: See TracChangeset for help on using the changeset viewer.