释放此互斥锁的正确方法是什么?

时间:2018-07-11 19:38:23

标签: multithreading assembly x86 x86-64 multicore

我正在使用以下x86-64程序集来获取和释放互斥锁:

.data

align   16
mtx:
    dd  0


.code

acquire_mutex PROC

lbl_retry:

    lock bts dword ptr [mtx], 1
    jnc     lbl_acquired

    pause
    jmp lbl_retry

lbl_acquired:
    ret
acquire_mutex ENDP


release_mutex PROC

    mov dword ptr [mtx], 0

    ret
release_mutex ENDP

我的问题是。我是否可以正确释放互斥锁?还是我需要这样的lock

release_mutex PROC

    lock and dword ptr [mtx], 0

    ret
release_mutex ENDP

0 个答案:

没有答案