[英]why TABLOCKX does not have deadlock
I need help to understand why tablockx does have deadlock in multithreaded application. 我需要帮助来理解为什么tablockx在多线程应用程序中确实存在死锁。
I tried tablockx with SqlQueryStress will multiple threads still i am not getting any deadlock 我尝试使用SqlQueryStress tablockx将多线程仍然没有任何死锁
Because deadlocks can pretty much only occur when you use row-level locking. 因为死锁几乎只会在使用行级锁定时发生。 The most basic example of a deadlock is:
死锁最基本的例子是:
Since A has 2 and needs 3, and B has 3 and needs 2, they will wait forever unless the query engine catches it, which is what causes a deadlock. 由于A有2并且需要3,而B有3并需要2,它们将永远等待,除非查询引擎捕获它,这是导致死锁的原因。 Basically it's an infinite logical loop of waits that get cancelled.
基本上它是一个被取消的等待的无限逻辑循环。
When you use a TABLOCK
, which indicates to the engine to use table locking instead of row locking, Transaction A would either wait for the whole table to be available if B already had it open, or would place a lock on the whole table if it were available, blocking any other transaction from modifying the table until it is complete. 当你使用
TABLOCK
,它指示引擎使用表锁定而不是行锁定时,如果B已经打开它,事务A将等待整个表可用,或者如果它已经锁定整个表可用,阻止任何其他事务修改表,直到它完成。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.