R16B02 erl_db.c:1272
/* we create table outside any table lock
* and take the unusal cost of destroy table if it
* fails to find a slot
*/
{
DbTable init_tb;
erts_smp_atomic_init_nob(&init_tb.common.memory_size, 0);
tb = (DbTable*) erts_db_alloc(ERTS_ALC_T_DB_TABLE,
&init_tb, sizeof(DbTable));
erts_smp_atomic_init_nob(&tb->common.memory_size,
erts_smp_atomic_read_nob(&init_tb.common.memory_size));
}我的任务。为什么要这样做?init_tb仅使用common.memory_size字段。为什么不使用int替换呢?
发布于 2013-10-16 17:03:41
希望我已经理解了你的实际问题..
我们可以从代码本身了解到,erlang VM使用SMP模式(简单地说,多核上有多个erlang调度器)。在这种情况下,最好的方法(在性能方面)是使用原子操作而不是锁。在内部,您所指向的操作可能正在使用本机CAS http://en.wikipedia.org/wiki/Compare-and-swap操作。
https://stackoverflow.com/questions/19394102
复制相似问题