Skip to content

对锁的一些认知有那些所的疑问 #175

@yngil

Description

@yngil

在表中加入一个同步状态字段,每次获取锁的是加 1 ,释放锁的时候-1,当状态为 0 的时候就删除这条记录,即释放锁。

实现重入锁时,并不能区分当前线程是否就是锁的持有者

insert into `t_lock`(`id`,`count`) values(1,1); 
update `t_lock` set `count` = `count`-1 where `id` = 1 and `count`>0;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions