/
usr
/
share
/
guile
/
2.0
/
ice-9
/
/usr/share/guile/2.0/ice-9
mkdir
upload
Name
Size
Mode
Actions
and-let-star.scm
2593
0644
edit
dl
rm
binary-ports.scm
1921
0644
edit
dl
rm
boot-9.scm
154720
0644
edit
dl
rm
buffered-input.scm
4935
0644
edit
dl
rm
calling.scm
10790
0644
edit
dl
rm
channel.scm
5312
0644
edit
dl
rm
command-line.scm
18655
0644
edit
dl
rm
common-list.scm
9160
0644
edit
dl
rm
control.scm
4036
0644
edit
dl
rm
curried-definitions.scm
1829
0644
edit
dl
rm
debug.scm
1114
0644
edit
dl
rm
deprecated.scm
31993
0644
edit
dl
rm
documentation.scm
7432
0644
edit
dl
rm
eval-string.scm
2997
0644
edit
dl
rm
eval.scm
21354
0644
edit
dl
rm
expect.scm
5628
0644
edit
dl
rm
format.scm
76284
0644
edit
dl
rm
ftw.scm
24753
0644
edit
dl
rm
futures.scm
11186
0644
edit
dl
rm
gap-buffer.scm
10384
0644
edit
dl
rm
getopt-long.scm
16888
0644
edit
dl
rm
hash-table.scm
1813
0644
edit
dl
rm
hcons.scm
2614
0644
edit
dl
rm
history.scm
2343
0644
edit
dl
rm
i18n.scm
17778
0644
edit
dl
rm
iconv.scm
3735
0644
edit
dl
rm
lineio.scm
3941
0644
edit
dl
rm
list.scm
1319
0644
edit
dl
rm
local-eval.scm
9946
0644
edit
dl
rm
ls.scm
3275
0644
edit
dl
rm
mapping.scm
4955
0644
edit
dl
rm
match.scm
2045
0644
edit
dl
rm
match.upstream.scm
36459
0644
edit
dl
rm
networking.scm
3407
0644
edit
dl
rm
null.scm
1157
0644
edit
dl
rm
occam-channel.scm
7436
0644
edit
dl
rm
optargs.scm
16123
0644
edit
dl
rm
poe.scm
3382
0644
edit
dl
rm
poll.scm
6166
0644
edit
dl
rm
popen.scm
5806
0644
edit
dl
rm
posix.scm
2793
0644
edit
dl
rm
pretty-print.scm
16211
0644
edit
dl
rm
psyntax-pp.scm
166774
0644
edit
dl
rm
psyntax.scm
147118
0644
edit
dl
rm
q.scm
4297
0644
edit
dl
rm
quasisyntax.scm
5348
0644
edit
dl
rm
r4rs.scm
9645
0644
edit
dl
rm
r5rs.scm
1602
0644
edit
dl
rm
r6rs-libraries.scm
9164
0644
edit
dl
rm
rdelim.scm
7648
0644
edit
dl
rm
readline.scm
9786
0644
edit
dl
rm
receive.scm
1082
0644
edit
dl
rm
regex.scm
9084
0644
edit
dl
rm
runq.scm
8379
0644
edit
dl
rm
rw.scm
1047
0644
edit
dl
rm
safe-r5rs.scm
3814
0644
edit
dl
rm
safe.scm
1275
0644
edit
dl
rm
save-stack.scm
2197
0644
edit
dl
rm
scm-style-repl.scm
11986
0644
edit
dl
rm
serialize.scm
3859
0644
edit
dl
rm
session.scm
18143
0644
edit
dl
rm
slib.scm
1583
0644
edit
dl
rm
stack-catch.scm
1983
0644
edit
dl
rm
streams.scm
7488
0644
edit
dl
rm
string-fun.scm
8798
0644
edit
dl
rm
syncase.scm
1556
0644
edit
dl
rm
threads.scm
6388
0644
edit
dl
rm
time.scm
2088
0644
edit
dl
rm
top-repl.scm
2812
0644
edit
dl
rm
unicode.scm
1005
0644
edit
dl
rm
vlist.scm
22081
0644
edit
dl
rm
weak-vector.scm
1288
0644
edit
dl
rm
Edit:
/usr/share/guile/2.0/ice-9/serialize.scm
(3859B)
;;;; Copyright (C) 2003, 2006 Free Software Foundation, Inc. ;;;; ;;;; This library is free software; you can redistribute it and/or ;;;; modify it under the terms of the GNU Lesser General Public ;;;; License as published by the Free Software Foundation; either ;;;; version 3 of the License, or (at your option) any later version. ;;;; ;;;; This library is distributed in the hope that it will be useful, ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;;;; Lesser General Public License for more details. ;;;; ;;;; You should have received a copy of the GNU Lesser General Public ;;;; License along with this library; if not, write to the Free Software ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ;;;; ;;; Commentary: ;; (serialize FORM1 ...) and (parallelize FORM1 ...) are useful when ;; you don't trust the thread safety of most of your program, but ;; where you have some section(s) of code which you consider can run ;; in parallel to other sections. ;; ;; They "flag" (with dynamic extent) sections of code to be of ;; "serial" or "parallel" nature and have the single effect of ;; preventing a serial section from being run in parallel with any ;; serial section (including itself). ;; ;; Both serialize and parallelize can be nested. If so, the ;; inner-most construct is in effect. ;; ;; NOTE 1: A serial section can run in parallel with a parallel ;; section. ;; ;; NOTE 2: If a serial section S is "interrupted" by a parallel ;; section P in the following manner: S = S1 P S2, S2 is not ;; guaranteed to be resumed by the same thread that previously ;; executed S1. ;; ;; WARNING: Spawning new threads within a serial section have ;; undefined effects. It is OK, though, to spawn threads in unflagged ;; sections of code where neither serialize or parallelize is in ;; effect. ;; ;; A typical usage is when Guile is used as scripting language in some ;; application doing heavy computations. If each thread is ;; encapsulated with a serialize form, you can then put a parallelize ;; form around the code performing the heavy computations (typically a ;; C code primitive), enabling the computations to run in parallel ;; while the scripting code runs single-threadedly. ;; ;;; Code: (define-module (ice-9 serialize) :use-module (ice-9 threads) :export (call-with-serialization call-with-parallelization) :export-syntax (serialize parallelize)) (define serialization-mutex (make-mutex)) (define admin-mutex (make-mutex)) (define owner #f) (define (call-with-serialization thunk) (let ((outer-owner #f)) (dynamic-wind (lambda () (lock-mutex admin-mutex) (set! outer-owner owner) (if (not (eqv? outer-owner (dynamic-root))) (begin (unlock-mutex admin-mutex) (lock-mutex serialization-mutex) (set! owner (dynamic-root))) (unlock-mutex admin-mutex))) thunk (lambda () (lock-mutex admin-mutex) (if (not (eqv? outer-owner (dynamic-root))) (begin (set! owner #f) (unlock-mutex serialization-mutex))) (unlock-mutex admin-mutex))))) (define-macro (serialize . forms) `(call-with-serialization (lambda () ,@forms))) (define (call-with-parallelization thunk) (let ((outer-owner #f)) (dynamic-wind (lambda () (lock-mutex admin-mutex) (set! outer-owner owner) (if (eqv? outer-owner (dynamic-root)) (begin (set! owner #f) (unlock-mutex serialization-mutex))) (unlock-mutex admin-mutex)) thunk (lambda () (lock-mutex admin-mutex) (if (eqv? outer-owner (dynamic-root)) (begin (unlock-mutex admin-mutex) (lock-mutex serialization-mutex) (set! owner outer-owner)) (unlock-mutex admin-mutex)))))) (define-macro (parallelize . forms) `(call-with-parallelization (lambda () ,@forms)))
Save
cmd:
run