Wiki
Download
Manual
Eggs
API
Tests
Bugs
show
edit
history
You can edit this page using
wiki syntax
for markup.
Article contents:
== Outdated egg! This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for [[/eggref/5/synch|the CHICKEN 5 version of this egg]], if it exists. If it does not exist, there may be equivalent functionality provided by another egg; have a look at the [[https://wiki.call-cc.org/chicken-projects/egg-index-5.html|egg index]]. Otherwise, please consider porting this egg to the current version of CHICKEN. [[tags: egg]] == synch Simple critical region helpers. [[toc:]] == Documentation Where {{MUTEX-FORM}} below the following forms are accepted: ; {{MUTEX-OBJECT}} : mutex ; {{(MUTEX-OBJECT [(LOCK-ARG...) [(UNLOCK-ARG...)]])}} : mutex w/ optional lock and unlock arguments === Synchronized Invocation - Continuation Safe These forms have the mutex lock/unlock wrapped in '''{{dynamic-wind}}'''. ==== synch <macro>(synch MUTEX-FORM [BODY ...]) -> *</macro> Execute {{BODY ...}} while {{MUTEX}} locked. Returns the result of {{BODY ...}}. ==== synch-with <macro>(synch-with MUTEX-FORM VARIABLE [BODY ...]) -> *</macro> Execute {{BODY ...}} while {{MUTEX}} locked and the mutex-specific of {{MUTEX}} bound to {{VARIABLE}}. Returns the result of {{BODY ...}}. ==== call-synch <macro>(call-synch MUTEX-FORM PROCEDURE [ARGUMENTS ...]) -> *</macro> Invoke {{PROCEDURE}} on the argument list {{ARGUMENTS ...}} while {{MUTEX}} locked. Returns the result of the {{PROCEDURE}} invocation. ==== call-synch-with <macro>(call-synch-with MUTEX-FORM PROCEDURE [ARGUMENTS ...]) -> *</macro> Invoke {{PROCEDURE}} on the mutex-specific of {{MUTEX}} and the {{ARGUMENTS ...}} while {{MUTEX}} locked. Returns the result of the {{PROCEDURE}} invocation. ==== apply-synch <macro>(apply-synch MUTEX-FORM PROCEDURE [ARGUMENTS ...]) -> *</macro> Apply {{PROCEDURE}} to the argument list {{ARGUMENTS ...}} while {{MUTEX}} locked. Returns the result of the {{PROCEDURE}} application. ==== apply-synch-with <macro>(apply-synch-with MUTEX-FORM PROCEDURE [ARGUMENTS ...]) -> *</macro> Apply {{PROCEDURE}} to the mutex-specific of {{MUTEX}}) and the {{ARGUMENTS ...}} while {{MUTEX}} locked. Returns the result of the {{PROCEDURE}} application. ==== synch-lock <macro>(synch-lock MUTEX-FORM [BODY ...]) -> *</macro> Execute {{BODY ...}} while {{MUTEX}} locked, and leave mutex locked. Returns the result of {{BODY ...}}. ==== synch-unlock <macro>(synch-unlock MUTEX-FORM [BODY ...]) -> *</macro> Execute {{BODY ...}} while {{MUTEX}} locked, and leave mutex unlocked. Returns the result of {{BODY ...}}. Should the mutex be unlocked a warning is issued and the mutex is locked before executing the {{BODY}}. ==== let-synch-with <macro>(let-synch-with BINDINGS [BODY ...]) -> *</macro> {{BINDINGS}} is a list of {{(VARIABLE MUTEX-FORM)}}. Expands into a nested {{(synch-with MUTEX-FORM VARIABLE ...}} form, a '''{{synch-with}}''' for each binding pair in {{BINDINGS}}. The leftmost binding pair is the outermost. Returns the result of {{BODY ...}}. ==== set!-synch-with <macro>(set!-synch-with MUTEX-FORM VARIABLE [BODY ...]) -> *</macro> While the {{MUTEX}} is locked, evaluates {{BODY ...}} with the {{VARIABLE}} bound to the mutex-specific of {{MUTEX}}. Sets the mutex-specific of {{MUTEX}} to the result of the evaluation. Returns the new mutex-specific of {{MUTEX}}. ==== object-synch-cut-with <macro>(object-synch-cut-with MUTEX-FORM [BODY ...]) -> *<-macro> Execute {{BODY ...}} while {{MUTEX}} locked. The top-level forms of {{BODY ...}} are parsed for occurrences of {{><}}. All such occurrences are replaced by the mutex-specific of {{MUTEX}}. Returns the result of {{BODY ...}}. ==== record-synch <macro>(record-synch RECORD-OBJECT RECORD-SYMBOL [BODY ...]) -> *</macro> Execute {{BODY ...}} while the {{RECORD-OBJECT}} mutex is locked. The mutex is a field of the record named {{RECORD-SYMBOL-mutex}}. Returns the result of {{BODY ...}}. <enscript language=scheme> (define-record-type foo (make-foo a b mtx) foo? (a foo-a) (b foo-b) (mtx foo-mutex) ) (define f1 (make-foo 1 2 (make-mutex 'foo))) (record-synch foo f1 (+ (foo-a f1) (foo-b f1))) </enscript> ==== record-synch-lock <macro>(record-synch-lock RECORD-OBJECT RECORD-SYMBOL [BODY ...]) -> *</macro> Execute {{BODY ...}} while the {{RECORD-OBJECT}} mutex is locked, and leave the mutex locked. Returns the result of {{BODY ...}}. {{RECORD-SYMBOL}} and {{RECORD-OBJECT}} are per '''{{record-synch}}'''. ==== record-synch-unlock <macro>(record-synch-unlock RECORD-OBJECT RECORD-SYMBOL [BODY ...]) -> *</macro> Execute {{BODY ...}} while the {{RECORD-OBJECT}} mutex is locked, and leave the mutex unlocked. Returns the result of {{BODY ...}}. {{RECORD-SYMBOL}} and {{RECORD-OBJECT}} are per '''{{record-synch}}'''. Should the mutex be unlocked a warning is issued and the mutex is locked before executing the {{BODY}}. === Synchronized Invocation - Continuation Unsafe These forms do not have the mutex lock/unlock wrapped in '''{{dynamic-wind}}''', otherwise the same behavior. ==== %call-synch <macro>(%call-synch MUTEX-FORM PROCEDURE [ARGUMENTS ...]) -> *</macro> ==== %call-synch-with <macro>(%call-synch-with MUTEX-FORM PROCEDURE [ARGUMENTS ...]) -> *</macro> ==== %apply-synch <macro>(%apply-synch MUTEX-FORM PROCEDURE [ARGUMENTS ...]) -> *</macro> ==== %apply-synch-with <macro>(%apply-synch-with MUTEX-FORM PROCEDURE [ARGUMENTS ...]) -> *</macro> ==== %synch <macro>(%synch MUTEX-FORM [BODY ...]) -> *</macro> ==== %synch-with <macro>(%synch-with MUTEX-FORM VARIABLE [BODY ...]) -> *</macro> ==== %synch-lock <macro>(%synch-lock MUTEX-FORM [BODY ...]) -> *</macro> ==== %synch-unlock <macro>(%synch-unlock MUTEX-FORM [BODY ...]) -> *</macro> ==== %let-synch <macro>(%let-synch BINDINGS [BODY ...]) -> *</macro> ==== %set!-synch-with <macro>(%set!-synch-with MUTEX-FORM VARIABLE [BODY ...]) -> *</macro> ==== %object-synch-cut-with <macro>(%object-synch-cut-with MUTEX-FORM [BODY ...]) -> *</macro> ==== %record-synch <macro>(%record-synch RECORD-OBJECT RECORD-SYMBOL [BODY ...]) -> *</macro> ==== %record-synch-lock <macro>(%record-synch-lock RECORD-OBJECT RECORD-SYMBOL [BODY ...]) -> *</macro> ==== %record-synch-unlock <macro>(%record-synch-unlock RECORD-OBJECT RECORD-SYMBOL [BODY ...]) -> *</macro> === Object Synchronization ==== make-synch-with-object <procedure>(make-synch-with-object OBJECT [NAME]) -> mutex</procedure> Returns a mutex with a mutex-specific value of {{OBJECT}}, and optional mutex {{NAME}}. {{NAME}} is either a symbol or a one element list of symbol. When a list the first element is used as the basis for a generated symbol. When a symbol it is used literally as the mutex name. When {{NAME}} is missing a generated symbol with the prefix '''{{synchobj}}''' is provided. ==== synch-with-object? <procedure>(synch-with-object? OBJECT [PREDICATE]) -> bool</procedure> Is the {{OBJECT}} a synchronized object - a mutex with a non-void mutex specific? The optional {{PREDICATE}} is used to verify the type of the mutex-specific binding. Otherwise any object is accepted. ==== define-constructor-synch <macro>(define-constructor-synch CTORNAME [ID])</macro> <enscript language=scheme> (define-constructor-synch make-hash-table hash-table-synch) ;=> similar (define (make-hash-table-sync . args) (make-synch-with-object (apply make-hash-table args) '(hash-table-synch)) ) </enscript> ==== define-predicate-synch <macro>(define-predicate-synch PREDNAME)</macro> <enscript language=scheme> (define-predicate-synch hash-table?) ;=> similar (define (hash-table?-sync obj) (synch-with-object? obj hash-table?)) </enscript> ==== define-operation-synch <macro>(define-operation-synch OPERNAME)</macro> Note that the operand must be the first argument of {{OPERNAME}}. <enscript language=scheme> (define-operation-synch hash-table-set!) ;=> similar (define (hash-table-set!-sync mtx+obj . args) (let ((mtx (if (pair? mtx+obj) (car mtx+obj) mtx+obj))) (check-mutex+object 'hash-table-set!-synch mtx 'object-synch) (synch-with mtx+obj obj (apply hash-table-set! obj args)) ) ) </enscript> ==== define-operation-%synch <macro>(define-operation-%synch OPERNAME)</macro> Note that the operand must be the first argument of {{OPERNAME}}. ==== synchronized-procedure <procedure>(synchronized-procedure PROC) -> procedure</procedure> Returns a synchronized version of {{PROC}} == Usage <enscript language=scheme> (require-extension synch) </enscript> or <enscript language=scheme> (require-library synch) ... (import synch) </enscript> == Notes * Inspired by Thomas Chust. == Bugs & Limitations * {{define-*-synch}} is obtuse. == Author [[/users/kon-lovett|Kon Lovett]] == Requirements [[/man/4/Unit srfi-18|Unit srfi-18]] [[/man/4/check-errors|check-errors]] [[setup-helper|setup-helper]] == Version history ; 2.4.1 : Fix lock failure handling. ; 2.4.0 : ; 2.3.0 : Add {{critical-region}}, {{synchronized-procedure}}, {{record-synch}}, {{record-synch-lock}}, {{record-synch-unlock}}, {{call-synch}}, {{call-synch-with}}, {{apply-synch}}, {{apply-synch-with}}, {{let-synch-with}}, {{set!-synch-with}}, {{synch-lock}}, {{synch-unlock}}, {{object-synch-cut-with}}, {{make-synch-with-object}}, {{synch-with-object?}}, {{define-constructor-synch}}, {{define-predicate-synch}}, {{define-operation-synch}}. ; 2.2.2 : ; 2.2.1 : Do not build {{format-synch}}. ; 2.2.0 : Deprecate {{../synch}} bindings. Add 'format-synch.scm'. ; 2.1.4 : . ; 2.1.3 : . ; 2.1.2 : Ensure all local vars in operation macros hygenic. ; 2.1.1 : Fix {{%record/synch}} body expansion. Fix {{make-object/synch}} default name. ; 2.1.0 : Support for mutex lock/unlock arguments. Operation wrapper macros. ; 2.0.0 : Port to hygienic Chicken. Removed 'set-object!/synch'. == License Copyright (C) 2009-2018 Kon Lovett. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the Software), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED ASIS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Description of your changes:
I would like to authenticate
Authentication
Username:
Password:
Spam control
What do you get when you multiply 1 by 8?