gpt4 book ai didi

erlang - ETS 批量操作是原子的吗?

转载 作者:行者123 更新时间:2023-12-02 01:10:18 27 4
gpt4 key购买 nike

具体来说,:ets.tab2list:ets.file2tab。这些函数是否“快照”表状态,或者其他操作是否可以在这些函数完成时交错读取和写入?

最佳答案

基于文档 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调用 ets:match_object/2,这是一个用 C 实现的内置函数 (BIF)。实现 here正在使用 BIF ets_select2,它是 ets:select/2 的实现。

ets:file2tab 结束调用 load_table/3它只使用 ets:insert/2

ets:tab2file/3 的代码在ets.erl , 使用 ets:select/3获取第一个 block 然后是ets:select/1获取表中的其余 block 。

关于erlang - ETS 批量操作是原子的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45406803/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com