next up previous
Next: Examples of Parallel Language Up: Implementing Parallel Language Constructs Previous: Parallel Languages and Reflection

  
Base Language ABCL/f

We first introduce the basic (i.e., non-reflective) language ABCL/f, a concurrent object-oriented language[16]. In ABCL/f, multiple-threading and synchronization are controlled via future and touch mechanisms4. An object is an instance of a class, embodying shared mutable data. Messages (or methods) sent to an object are asynchronous, and dispatched according to its class, and mutually excluded in order to preserve consistency.
  
Figure 1: Sample code fragment of ABCL/ f

;;; class definition
(defclass account ()
((balance :initform 0)))

;;; method definition
(defmethod account deposit (amount)
(setf balance (+ balance amount))
balance)

;;; object creation and method invocation
(let ((acc (make-account :balance 100)))
(print "Current balance: " (deposit acc 50)))

;;; use of the future and touch
(let ((acc (make-account :balance 100)))
(let ((rbox (future (deposit acc 30))))
(some computation)
(print "Current balance: " (touch rbox))))




Figure 1 shows an example program in ABCL/f. The first expression defines a class account with an instance variable balance. The second expression defines a method deposit for the class account. This method adds the given amount to the instance variable balance, and returns the updated value. The third expression shows how an object is created and manipulated; (make-account ...) creates an object of the class account; finally, (deposit acc 50) invokes the method deposit of object acc with argument 50. The fourth expression illustrates typical use of future. The future form invokes a method of object acc, but the caller does not block and wait for the end of the method execution. Instead, it receives a ``reply box,'' in which the result of the method will be stored. After the end of (some computation), the caller extracts the result from the reply box using the touch form. If the result is not ready (i.e., the method deposit has not finished yet), the caller is blocked until it becomes available. The future form can also be used for function invocations. In this case, the function invocation is concurrently executed by a newly created thread. In addition, the future form can take an optional argument ``:on p'', which specifies the processor ID where the function will be executed.
next up previous
Next: Examples of Parallel Language Up: Implementing Parallel Language Constructs Previous: Parallel Languages and Reflection
Matt Hurlbut
1998-07-14