ETS 批量操作是原子的吗?

Are ETS bulk operations atomic?

具体来说,:ets.tab2list:ets.file2tab。这些功能 "snapshot" 是否处于 table 状态,或者其他操作是否可以在这些功能完成时交错读取和写入?

基于文档here

Functions that internally traverse over a table, like select and match, give the same guarantee as safe_fixtable.

在哪里

[...] function safe_fixtable can be used to guarantee that a sequence of first/1 and next/2 calls traverse the table without errors and that each existing object in the table is visited exactly once, even if another (or the same) process simultaneously deletes or inserts objects into the table.

与您的问题具体相关:

Nothing else is guaranteed; in particular objects that are inserted or deleted during such a traversal can be visited once or not at all.


编辑

ets:tab2list/1 calls ets:match_object/2 which is a built-in function (BIF) implemented in C. The implementation here 使用 BIF ets_select2,这是 ets:select/2.

的实现

ets:file2tab 最终调用 load_table/3,它只使用 ets:insert/2.

ets.erl, uses ets:select/3 to get the first chunk and then ets:select/1ets:tab2file/3 的代码,用于获取 table 中的其余块。