Next Previous Up Top Contents Index

conditional-update!

atomic-increment!

Function macro

Summary

Atomically increments a place containing a numeric value.

Macro call

atomic-increment!(place);
atomic-increment!(place, by);

Arguments

place
A Dylan variable-namebnf.

If the implementation provides the extended form of conditional-update!, place can also be a function call.

by
An instance of <object>. Default value: 1.

Values

new-value
An instance of <object>.

Library

threads

Module

threads 

Description

Atomically increments a place containing a numeric value.

The value of the place is evaluated one or more times to determine the initial value. A new value is computed from this value and by, by applying + from the Dylan module. The new value is atomically stored back into place.

The macro returns the new value of place.

The place must be a suitable place for conditional-update!.

Implementations of atomic-increment! are permitted to use conditional-update! (as in the described example), and hence can involve a loop and can cause place to be evaluated more than once. However, an atomic increment of a locked variable might be implemented by a more efficient non-looping mechanism on some platforms.

Example

The following example atomically increments *number-detected* by 2, and returns the incremented value.

atomic-increment!(*number-detected*, 2);

Common Dylan and Functional Extensions - 31 Mar 00

Next Previous Up Top Contents Index