* boot-9.scm (load): rewritten again.
[bpt/guile.git] / ice-9 / threads.scm
1 ;;;; Copyright (C) 1996 Free Software Foundation, Inc.
2 ;;;;
3 ;;;; This program is free software; you can redistribute it and/or modify
4 ;;;; it under the terms of the GNU General Public License as published by
5 ;;;; the Free Software Foundation; either version 2, or (at your option)
6 ;;;; any later version.
7 ;;;;
8 ;;;; This program is distributed in the hope that it will be useful,
9 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 ;;;; GNU General Public License for more details.
12 ;;;;
13 ;;;; You should have received a copy of the GNU General Public License
14 ;;;; along with this software; see the file COPYING. If not, write to
15 ;;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
16 ;;;;
17 ;;;; ----------------------------------------------------------------
18 ;;;; threads.scm -- User-level interface to Guile's thread system
19 ;;;; 4 March 1996, Anthony Green <green@cygnus.com>
20 ;;;; Modified 5 October 1996, MDJ <djurfeldt@nada.kth.se>
21 ;;;; ----------------------------------------------------------------
22 ;;;;
23 \f
24
25 (define-module #/ice-9/threads)
26
27 \f
28
29 ; --- MACROS -------------------------------------------------------
30
31 (defmacro-public make-thread (fn . args)
32 `(call-with-new-thread
33 (lambda ()
34 (,fn ,@args))
35 (lambda args args)))
36
37 (defmacro-public begin-thread (first . thunk)
38 `(call-with-new-thread
39 (lambda ()
40 (begin
41 ,first ,@thunk))
42 (lambda args args)))
43
44 (defmacro-public with-mutex (m . thunk)
45 `(dynamic-wind
46 (lambda () (lock-mutex ,m))
47 (lambda () (begin ,@thunk))
48 (lambda () (unlock-mutex ,m))))
49
50 (defmacro-public monitor (first . thunk)
51 `(with-mutex ,(make-mutex)
52 (begin
53 ,first ,@thunk)))