自相矛盾:一个进程可以自成死锁么?
崔华,网名 dbsnake
Oracle ACE Director,ACOUG 核心专家
编辑手记:感谢崔华授权我们独家转载其精品文章,也欢迎大家向“Oracle”社区投稿。在新年前,轻松一点,看看崔华这篇小文,通过一个简单的例子,理解Oracle的自制事务、死锁,建议大家动手去测试、尝试,从而从中学到更多的知识。
有朋友问我:“一个transaction会自我死锁吗?也就是自己锁死了自己”。
很凑巧,半个月前我刚好帮同事处理过这种自我死锁的情况。
我们这里来构造一个自我死锁的例子:
select sid from v$mystat
where rownum
SID
———-
362
SQL create table t1 (id varchar2(10),
amount number(10));
Table created
SQL insert into t1 values(cuihua,100);
1 row inserted
SQL commit;
Commit complete
SQL select * from t1;
ID AMOUNT
———- ———–
cuihua 100
SQL create procedure p_autonomous is
2 PRAGMA AUTONOMOUS_TRANSACTION;
3 begin
4 update t1 set amount=102
5 where id=cuihua;
6 commit;
7 end;
8 /
Procedure created
SQL create procedure p_test is
2 begin
3 update t1 set amount=101 where id=cuihua;
4 p_autonomous;
5 commit;
6 end;
7 /
Procedure created
现在只要我执行上述存储过程p_test,就会产生自我死锁,如下所示:
此时alert log里会显示:
ORA-00060: Deadlock detected.
More info in file /u01/app/oracle/admin/ipra/udump/ipra_ora_921828.trc.
从上述trace文件里我们可以看到:
也就是说这里的Blocker是session 362,Waiter也是session 362,典型的自己锁死了自己。
不知道我为什么要这样构造的朋友们看了如下这样一段话就什么都明白了:
The Oracle server provides the ability to temporarily suspend a current transaction and begin another. This second transaction is known as an autonomous transaction and runs independently of its parent. The autonomous or child transaction can commit or rollback as applicable, with the execution of the parent transaction being resumed upon its completion.
The parent may then perform further operations and commit or roll back without affecting the outcome of any operations performed within the child. The child transaction does not inherit transaction context (that is, SET TRANSACTION statements). The transactions are organized as a stack: Only the “top” transaction is accessible at any given time. Once completed, the autonomous transaction is “popped” and the calling transaction is again visible. The limit to the number of suspended transactions is governed by the initialization parameter TRANSACTIONS.
The Oracle server uses similar functionality internally in recursive transactions.
Transactions must be explicitly committed or rolled back or an error ORA-6519 is signaled when attempting to return from the autonomous block.
A deadlock situation may occur where a called and calling transaction deadlock; — this is not prevented, but is signaled by an error unique to this situation. The application developer is responsible for avoiding this situation.
本文出自数据和云公众号,原文链接
线程和进程 / 进程和线程的区别和联系 每个应用程序运行于现代操作系统之上时,操作系统会提供一种抽象,好像系统上只有这个程序在运行,所有的硬件资源都被这个程序在使用。这种假象是通过抽象了一个进程的概念来完成的,进程可以说是计算机科学中最重要和最成功的概念之一.
今天,进程告诉我线程它它它它不想活了(二) 这篇文章我们来探讨它们是如何通信的,进程告诉我说线程不想活了,我不管它死活,我是谁?进程是怎么告诉我的?进程的出现和线程的死亡和我有必然联系吗?文章为你揭露哟...
今天,进程告诉我线程它它它它不想活了(三) 这篇文章我们来探讨它们是如何通信的,进程告诉我说线程不想活了,我不管它死活,我是谁?进程是怎么告诉我的?进程的出现和线程的死亡和我有必然联系吗?文章为你揭露哟...
相关文章
- X32进程注入x64DLL到x64进程
- Win64 驱动内核编程-21.DKOM隐藏和保护进程
- python多进程管道通信(精)
- Linux 进程间通信(二) 管道
- Linux 有问必答:如何知道进程运行在哪个 CPU 内核上?
- c#中一个进程启动另一个进程并传递参数
- MFC:通过代码简单理解进程间的通讯机制——共享内存
- linux下如何提高一个进程的优先级?
- linux进程一个阻塞 I/O 的例子
- 配置一个Oracle共享服务器进程环境需要哪两项参数
- linux下查看一个进程的启动时间和运行时间
- 进程间是如何通信的
- C# 控制台程序 不显示在任务栏 只在进程中显示
- mysql的大量的sleep进程解决办法
- 【Android】使用AIDL实现进程间传递对象案例
- Linux 进程管理命令