*** empty log message ***
[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, Inc., 59 Temple Place, Suite 330,
16 ;;;; Boston, MA 02111-1307 USA
17 ;;;;
18 ;;;; ----------------------------------------------------------------
19 ;;;; threads.scm -- User-level interface to Guile's thread system
20 ;;;; 4 March 1996, Anthony Green <green@cygnus.com>
21 ;;;; Modified 5 October 1996, MDJ <djurfeldt@nada.kth.se>
22 ;;;; ----------------------------------------------------------------
23 ;;;;
24 \f
25
26 (define-module #/ice-9/threads)
27
28 \f
29
30 ; --- MACROS -------------------------------------------------------
31
32 (defmacro-public make-thread (fn . args)
33 `(call-with-new-thread
34 (lambda ()
35 (,fn ,@args))
36 (lambda args args)))
37
38 (defmacro-public begin-thread (first . thunk)
39 `(call-with-new-thread
40 (lambda ()
41 (begin
42 ,first ,@thunk))
43 (lambda args args)))
44
45 (defmacro-public with-mutex (m . thunk)
46 `(dynamic-wind
47 (lambda () (lock-mutex ,m))
48 (lambda () (begin ,@thunk))
49 (lambda () (unlock-mutex ,m))))
50
51 (defmacro-public monitor (first . thunk)
52 `(with-mutex ,(make-mutex)
53 (begin
54 ,first ,@thunk)))