multithreading - Atomic Operations for Multithreading in SBCL
问题描述
I'm getting an error when loading a function that contains an atomic operation. As a simple example, the file test.lisp contains:
(defparameter *count* 0)
(defun test ()
(sb-ext:atomic-incf *count*))
which generates the following error:
* (load "d:\\test.lisp")
; file: d:/test.lisp
; in: DEFUN TEST
; (ATOMIC-INCF *COUNT*)
;
; caught ERROR:
; during macroexpansion of (ATOMIC-INCF *COUNT*). Use *BREAK-ON-SIGNALS* to
; intercept.
;
; Invalid first argument to ATOMIC-INCF: *COUNT*
;
; compilation unit finished
; caught 1 ERROR condition
T
*
Why is *count*
invalid?
解决方案
从文档字符串:
PLACE must access one of the following:
- a DEFSTRUCT slot with declared type (UNSIGNED-BYTE 64)
or AREF of a (SIMPLE-ARRAY (UNSIGNED-BYTE 64) (*))
The type SB-EXT:WORD can be used for these purposes.
- CAR or CDR (respectively FIRST or REST) of a CONS.
- a variable defined using DEFGLOBAL with a proclaimed type of FIXNUM.
Macroexpansion is performed on PLACE before expanding ATOMIC-INCF.
我怀疑这些是为了在进行比较和交换时避免运行时检查。
推荐阅读
- c# - 如何使用 C# REST API 查找和删除 Azure 存储容器?
- uwp - 在 uwp 中找不到名称/键 TopCornerRadiusFilterConverter 的资源
- python - 如何在python中返回类函数?
- javascript - 符号“&$checked”是什么意思
- reactjs - 如何在 axios.all 方法 React Native 中分配标头
- python - 如何使用 Robot Framework 按特定字段将数据更新为 CSV 文件
- node.js - 如何将 Angular 创建的 xml 传输到 node.js 中的文件
- python - 使用类型设置父类属性
- shell - 编译 xv6 代码但在汇编指令上给出错误
- python - 图像分类器错误该层的所有输入都应该是张量