哲学家吃面问题. Thread DeadLock and Starvation
 If each Philosopher does the following, it can cause
while(true) {
    think();
    take_fork(i);
    take_fork((i+1)%5);
    eat();
    put_fork(i);
    put_fork((i+1)% 5);
}
A. Deadlock
B. Starvation
C. All above

我的问题是,为什么这个会导致 A 跟 B 。 答案是 C。 谢谢大神回答

1个回答

因为死锁,导致eat没有执行,所以饿死了。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
哲学家吃面
哲学家吃面,多线程,解决死锁问题,java多线程
哲学家吃面问题.zip
哲学家吃面问题模拟,哲学家出于三种状态:思考、饥饿、吃面,系统产生随机数调用模拟哲学家吃面情况,代码由java编写,由7个类组成,按照MVC模式编写。课题是操作系统课程设计。内附实验报告
vc++实现哲学家吃面问题
vc++实现哲学家吃面问题 演示死锁与永不死锁状态 代码比较简单 便于理解
操作系统综合实验之哲学家吃面问题和实验报告
本程序需要用到的数据有:5个哲学家和一张圆桌子,桌子旁边有5个座位,桌子上放着5支筷子,每两个座位之间放一支,为了吃面,哲学家必须获得一双筷子,且每人只能直接从紧邻自己的左边或右边去取筷子。 ①哲学家是进程,有四种状态,分别是等待任务、思考、饥饿、就餐,用不同图片表示哲学家状态。 ②筷子是进程运行所需要的资源,有两种状态:被占用和空闲,筷子图片为空白时,资源被占用。 ③进程运行时间是由随机函数随机产生的,随机函数是以当前逝去时间作为随机种子,进程运行时间。
Linux下经典五位哲学家吃面模型分析
一、问题介绍        哲学家进餐问题是典型的同步问题。该问题是描述有五个哲学家共用一张圆桌,分别坐在周围的五张椅子上,在圆桌上有一碗面和五只筷子,他们的生活方式是交替地进行思考和进餐。平时,一个哲学家进行思考,饥饿时便试图取用其左右最靠近他的筷子,只有在他拿到两只筷子时才能进餐。进餐完毕,放下筷子继续思考。如下图所示:   2、解决办法  多线程版思路: 选用互斥锁mutex,如创...
starvation饿死问题
谁能谈谈关于starvation饿死问题吗?经典的哲学家就餐为例子。
小熊吃面
小熊吃面时间限制: 1 Sec  内存限制: 128 MB题目描述小熊Teddy非常爱吃面,每天晚上都要吃很多很多面。小熊晚上准备了泡面和拉面若干碗,但是吃法非常讲究:如果要吃泡面,必须连续吃k碗,不能多也不能少。小熊吃面少于a碗就会太饿,多于b碗就会太撑,只能吃a到b碗之间。请问有多少种吃法。由于答案可能非常大,所以输出时需要模1000000007。输入第一行有两个整数t和k(1<=t,k...
问题 : 小熊吃面
于a碗就会太饿,多于b碗就会太撑,只能吃a到b碗之间。请问有多少种吃法。由于答案可能非常大,所以输出时需要模1000000007。 输入 第一行有两个整数t和k(1<=t,k<=100000),代表有t组数据,每次必须连续吃k碗泡面。 接下来t行,每行有两个整数ai和bi(1<=ai<=bi<=100000),代表第i组数据。 输出 输出t行,每行一个整数,代表吃a到...
哲学科吃面问题
一个有界面的哲学家吃面问题,内含源代码。
deadlock 死锁问题
环境:interbase5.6 cb5.0rn我在用程序时,多台机子同时打开一样的程序时,出现“dead lock",请问怎么解决.
哲学家问题
这是一个哲学家就餐问题的程序,运用到多核多线程技术,可能有问题,希望大家指点
weblogic9.2出现DEADLOCK的问题
DEADLOCK DETECTED:rn==================rnrn[deadlocked thread] Javelin Worker-0-pageOne.jsp:rn------------------------------------------------rnThread 'Javelin Worker-0-pageOne.jsp' is waiting to acquire lock 'java.lang.Class@10cfe7c' that is held by thread 'Javelin Worker-0-pageOneClassroomUseRecord.jsp'rnrnStack trace:rn------------rn jrockit.vm.Threads.shortNap(Native Method)rn jrockit.vm.Locks.waitForThinRelease(Unknown Source)rn jrockit.vm.Locks.monitorEnterSecondStage(Unknown Source)rn jrockit.vm.Locks.monitorEnter(Unknown Source)rn javelin.jsp.tag.TagFileTagInfo.mergeTagInfo(TagFileTagInfo.java:112)rn javelin.jsp.tag.TagFileTagInfo.initAttributeTypes(TagFileTagInfo.java:356)rn javelin.jsp.JspActionChecker.checkActionStart(JspActionChecker.java:283)rn javelin.jsp.JspActionChecker.checkActions(JspActionChecker.java:213)rn javelin.jsp.JspActionChecker.checkActions(JspActionChecker.java:227)rn javelin.jsp.JspActionChecker.check(JspActionChecker.java:156)rn javelin.jsp.JspCheckContext.check(JspCheckContext.java:77)rn javelin.jsp.JspAnalyzer.check(JspAnalyzer.java:59)rn javelin.ProxySourceFile._check(ProxySourceFile.java:152)rn javelin.SourceFile.masterCheck(SourceFile.java:777)rn javelin.SourceFile.check(SourceFile.java:297)rn javelin.SourceFile.check(SourceFile.java:318)rn javelin.ProxySourceFile.codeGen(ProxySourceFile.java:222)rn javelin.SourceFile.codeGen(SourceFile.java:310)rn javelin.client.ClientUtilsImpl$CodeGenJob.run(ClientUtilsImpl.java:1105)rn javelin.client.Job.performJob(Job.java:81)rn javelin.client.ThreadPool$WorkerThread.run(ThreadPool.java:215)rn jrockit.vm.RNI.c2java(Native Method)rnrn[deadlocked thread] Javelin Worker-0-pageOneClassroomUseRecord.jsp:rn------------------------------------------------------------------rnThread 'Javelin Worker-0-pageOneClassroomUseRecord.jsp' is waiting to acquire lock 'javelin.jsp.tag.TagFileTagInfo@181c6a6' that is held by thread 'Javelin Worker-0-pageOne.jsp'rnrnStack trace:rn------------rn jrockit.vm.Threads.shortNap(Native Method)rn jrockit.vm.Locks.waitForThinRelease(Unknown Source)rn jrockit.vm.Locks.monitorEnterSecondStage(Unknown Source)rn jrockit.vm.Locks.monitorEnter(Unknown Source)rn javelin.jsp.tag.TagInfoEx.setTagExtraInfo(TagInfoEx.java:613)rn javelin.jsp.tag.TagInfoEx.copy(TagInfoEx.java:690)rn javelin.jsp.tag.TagFileTagInfo.mergeTagInfo(TagFileTagInfo.java:126)rn javelin.jsp.tag.TagFileTagInfo.initAttributeTypes(TagFileTagInfo.java:356)rn javelin.jsp.JspActionChecker.checkActionStart(JspActionChecker.java:283)rn javelin.jsp.JspActionChecker.checkActions(JspActionChecker.java:213)rn javelin.jsp.JspActionChecker.checkActions(JspActionChecker.java:227)rn javelin.jsp.JspActionChecker.check(JspActionChecker.java:156)rn javelin.jsp.JspCheckContext.check(JspCheckContext.java:77)rn javelin.jsp.JspAnalyzer.check(JspAnalyzer.java:59)rn javelin.ProxySourceFile._check(ProxySourceFile.java:152)rn javelin.SourceFile.masterCheck(SourceFile.java:777)rn javelin.SourceFile.check(SourceFile.java:297)rn javelin.SourceFile.check(SourceFile.java:318)rn javelin.ProxySourceFile.codeGen(ProxySourceFile.java:222)rn javelin.SourceFile.codeGen(SourceFile.java:310)rn javelin.client.ClientUtilsImpl$CodeGenJob.run(ClientUtilsImpl.java:1105)rn javelin.client.Job.performJob(Job.java:81)rn javelin.client.ThreadPool$WorkerThread.run(ThreadPool.java:215)rn jrockit.vm.RNI.c2java(Native Method)rnrn>rn<2007-10-23 下午01时46分11秒 CST> rn<2007-10-23 下午01时46分12秒 CST> rn<2007-10-23 下午01时46分12秒 CST> rn<2007-10-23 下午01时46分12秒 CST> <000000> <===== FULL THREAD DUMP ===============rnTue Oct 23 13:46:12 CST 2007rnrnrn应用采用struts+hibernate+spring框架,用weblogic9.2发布,数据库是oracle9。rn哪位大虾帮帮忙。分不够可以在加。多谢!!!
android inputdispatcher deadlock问题
大家好,我最近遇到一个zygote crash的问题。经过我对log的分析,发现是因为inputdispatcher死锁导致的。然后我跟踪了ANR的信息,发现这么个锁的情况。rn[color=#FF0000]"ActivityManager" prio=5 tid=11 MONITOR[/color]rn | group="main" sCount=1 dsCount=0 obj=0x405054f0 self=0x333e50rn | sysTid=258 nice=-2 sched=0/0 cgrp=default handle=3358728rn at com.android.server.am.ActivityManagerService$2.handleMessage(ActivityManagerService.java:~1201)rn - waiting to lock <0x40505700> (a com.android.server.am.ActivityManagerService) held by threadid=25 (InputDispatcher)rn at android.os.Handler.dispatchMessage(Handler.java:99)rn at android.os.Looper.loop(Looper.java:130)rn at com.android.server.am.ActivityManagerService$AThread.run(ActivityManagerService.java:1515)rnrnrn[color=#FF0000]"InputDispatcher" prio=10 tid=25 MONITOR[/color]rn | group="main" sCount=1 dsCount=0 obj=0x408bc4c8 self=0x64d428rn | sysTid=273 nice=-8 sched=0/0 cgrp=default handle=6592704rn at com.android.server.PackageManagerService.getPackageInfo(PackageManagerService.java:~1423)rn - waiting to lock <0x405bd1a0> (a java.util.HashMap) held by threadid=51 (Binder Thread #12)rn at com.android.server.am.ActivityManagerService.appendDropBoxProcessHeaders(ActivityManagerService.java:7170)rn at com.android.server.am.ActivityManagerService.addErrorToDropBox(ActivityManagerService.java:7221)rn at com.android.server.am.ActivityManagerService.appNotResponding(ActivityManagerService.java:3231)rn at com.android.server.am.ActivityRecord.keyDispatchingTimedOut(ActivityRecord.java:567)rn at com.android.server.WindowManagerService$InputMonitor.notifyANR(WindowManagerService.java:5390)rn at com.android.server.InputManager$Callbacks.notifyANR(InputManager.java:416)rn at dalvik.system.NativeStart.run(Native Method)rnrnrn[color=#FF0000]"Binder Thread #12" prio=5 tid=51 NATIVE[/color] --》最后跟到这rn | group="main" sCount=1 dsCount=0 obj=0x4075ac80 self=0x359468rn | sysTid=423 nice=-20 sched=0/0 cgrp=default handle=5168400rnrn at org.apache.harmony.luni.platform.OSFileSystem.write(Native Method)rn at dalvik.system.BlockGuard$WrappedFileSystem.write(BlockGuard.java:171)rn at java.io.FileOutputStream.write(FileOutputStream.java:300)rn at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:164)rn at java.io.OutputStreamWriter.convert(OutputStreamWriter.java:236)rn at java.io.OutputStreamWriter.write(OutputStreamWriter.java:225)rn at java.io.PrintWriter.doWrite(PrintWriter.java:690)rn at java.io.PrintWriter.write(PrintWriter.java:665)rn at java.io.PrintWriter.write(PrintWriter.java:640)rn at java.io.PrintWriter.write(PrintWriter.java:708)rn at java.io.PrintWriter.print(PrintWriter.java:468)rn at com.android.server.PackageManagerService$ActivityIntentResolver.dumpFilter(PackageManagerService.java:4345)rn at com.android.server.PackageManagerService$ActivityIntentResolver.dumpFilter(PackageManagerService.java:4209)rn at com.android.server.IntentResolver.dumpMap(IntentResolver.java:120)rn at com.android.server.IntentResolver.dump(IntentResolver.java:149)rn at com.android.server.PackageManagerService.dump(PackageManagerService.java:7330)rn at android.os.Binder.dump(Binder.java:256)rn at android.os.Binder.onTransact(Binder.java:224)rn at android.content.pm.IPackageManager$Stub.onTransact(IPackageManager.java:1097)rn at com.android.server.PackageManagerService.onTransact(PackageManagerService.java:1113)rn at android.os.Binder.execTransact(Binder.java:336)rn at dalvik.system.NativeStart.run(Native Method)rnrn最后 发现 是因为binder貌似 在写(write的时候占用了很长时间),我想问下什么情况下会出现这种情况,如何去解决 谢谢
IGlobalInterfaceTable::GetInterfaceFromGlobal deadlock 问题
一个VC8写的COM的dll,在一个c#写的程序里运行。rnrn那个COM DLL是STA,从外部收到一个COM接口,然后通过 IGlobalInterfaceTable::RegisterInterfaceInGlobal 注册好。程序运行起来后,会创建一个worker thread,在那个thread里需要用到那个接口,所以就用注册时得到的cookie通过IGlobalInterfaceTable::GetInterfaceFromGlobal去拿那个接口,然后就停在那里了,那个方法没有返回,没有异常抛出,也没有其他错误信息,怀疑是有deadlock出现。rnrn不知道哪位知道是怎么回事?
咨询死锁问题(deadlock)
当sql发现session A 阻塞了session B,形成deadlock时,系统在哪个时间节点,或者什么规则会kill掉阻塞的session。我这块知识不太清楚,是否有类似timeout的内容,到了时间点就kill进程。请大家帮助
oracle8.1.5 deadlock问题
oracle8.1.5中对deadlock问题如何处理?
deadlock问题请教
目前现象如下:rn在数据库中有一个表(大概有几十万条记录),有多个程序在定时插入记录rn我用一个测试程序查询符合条件的记录(一般是几千条记录,大概需要3秒钟左右)。rn我测试的时候有时候会出现deadlock异常(一般情况下,每4次有1次这种错误)rnrn请问:rn1 查询跟插入记录这两种操作会产生deadlock么?rn2 怎么样修改才能数据库不发生deadlock错误?rnrn谢谢。rnrnrn
deadlock问题,请进=>
程序中比较多的时候返回下列错误(Sybase 11.51):rnYour sever command(family id #0, process id #23) was deadlocked with another process and has been chosen as deadlock victim.Re-run your command.rn请帮忙看一下,多谢了!
java 用PV 实现哲学家吃面问题的一个线程问题 (在线等啊!)
[code=java]rnrnclass Semaphore rn int status; //筷子当前状态rn int num; //筷子编号rn public Semaphore(int status, int num) //筷子信号量rn this.status = status;rn this.num = num;rn rnrnrnrnrnrnpublic class philosopherProblem rn static Semaphore fork[] = new Semaphore[5];rn philosopher p[] = new philosopher[5];rn int pw[] = new int[5];rn rnrn public synchronized void P(philosopher phi, Semaphore fork) //p操作rn fork.status--;rn rn if (fork.status < 0) rn try rn pw[fork.num] = phi.num; //当筷子已经被占用的时候,用pw来记录哪根筷子有哲学家在等待。rn this.wait();rn rn catch (InterruptedException e) rnrn e.printStackTrace();rn rn rn rnrn public synchronized void V(philosopher phi, Semaphore fork) rn fork.status++;rnrn if (fork.status <= 0) rnrn rn if (pw[fork.status] != -1) //如果刚放下的筷子中有哲学家在等,则查看pw中是哪个哲学家,然后再运行这个哲学家线程 rn //notifyAll();rn p[ pw[fork.status] ].notify(); rn pw[fork.status] = -1;rnrn rn rn rn rnrn class philosopher extends Thread rn rn int num; //哲学家编号rn boolean isHungry; //哲学家是否饥饿rnrn rn public philosopher(int num) rn this.num = num ;rn rnrn public void run() rnrn while (true) rn // isHungry = Math.round(Math.random()*1) == 0 ? false : true;rn // if(isHungry)rn eat();rn // this.sleep(millis)rn // else rn /*rn * try think(); this.sleep(Math.round(Math.random()*1000)); rn * catch (InterruptedException e) // TODO Auto-generated catchrn * block e.printStackTrace(); rn */rn // rnrn rn rnrn public void eat() rn rn if (num % 2 == 1) rn P(this,fork[num] );rn System.out.println("哲学家" + num + "拿到左边第" + (num) + "号筷子");rn P(this,fork[(num+1)%5]);rn System.out.println("哲学家" + num + "拿到右边第" + (num+1) % 5 + "号筷子");rn try rn System.out.println("哲学家" + num + "在吃饭");rn this.sleep(1000);rn catch (InterruptedException e) rn e.printStackTrace();rn rn V(this, fork[num]);rn System.out.println("哲学家" + num + "放下左边第" + (num) + "号筷子");rn V(this, fork[(num+1)%5]);rn System.out.println("哲学家" + num + "放下右边第" + (num+1)%5 + "号筷子");rn else rn P(this,fork[(num+1)%5]);rn System.out.println("哲学家" + num + "拿到右边第" + (num+1) % 5 + "号筷子");rn P(this,fork[num] );rn System.out.println("哲学家" + num + "拿到左边第" + (num) + "号筷子");rnrn try rn System.out.println("哲学家" + num + "在吃饭");rn this.sleep(1000);rn catch (InterruptedException e) rn // TODO Auto-generated catch blockrn e.printStackTrace();rn rn V(this, fork[num]);rn System.out.println("哲学家" + num + "放下左边第" + (num) + "号筷子");rn V(this, fork[(num+1)%5]);rn System.out.println("哲学家" + num + "放下右边第" + (num+1)%5 + "号筷子");rnrn rnrn rnrn public void think() rn System.out.println("哲学家" + num + "在思考");rn rnrn rnrn rnrn public void init() rnrn for (int i = 0; i < 5; i++) //初始化5根筷子rn fork[i] = new Semaphore(1,i);rn rn for (int i = 0; i < 5; i++) //初始化5个哲学家和5个线程标志pwrn p[i] = new philosopher(i);rn pw[i] = -1;rn rn rnrn for (int i = 0; i < 5; i++) rn p[i].start();rn rnrn rnrn public static void main(String[] args) rnrn new philosopherProblem().init();rn rnrnrn[/code]rnrnrnrn这个里面老是在V操作的时候p[ pw[fork.status] ].notify();出现错误:rn[color=#FF0000]Exception in thread "Thread-0" java.lang.IllegalMonitorStateExceptionrn at java.lang.Object.notify(Native Method)rn at help.philosopherProblem.V(philosopherProblem.java:43)rn at help.philosopherProblem$philosopher.eat(philosopherProblem.java:109)rn at help.philosopherProblem$philosopher.run(philosopherProblem.java:66)rnException in thread "Thread-2" java.lang.IllegalMonitorStateExceptionrn at java.lang.Object.notify(Native Method)rn at help.philosopherProblem.V(philosopherProblem.java:43)rn at help.philosopherProblem$philosopher.eat(philosopherProblem.java:111)rn at help.philosopherProblem$philosopher.run(philosopherProblem.java:66)rn[/color]rnrnrn哪个高手可以帮忙一下啊,不胜感激。
Parallel Deadlock
DescriptionnnA common problem in parallel computing is establishing proper communication patterns so that processors do not deadlock while either waiting to receive messages from other processors, or waiting for the sending of messages to other processors to complete. That is, one processor will not complete sending a message until it is received by the destination processor. Likewise, a receive cannot complete until a message is actually sent. nnThere are two modes of communication: blocking and non-blocking. A blocking send will not complete until a matching receive is performed at the destination processor. Likewise, a blocking receive will not complete until the matching send is performed by the source processor. Non- blocking actions will ``return'' immediately (i.e., allow the program to continue), but will not actually complete until the matching action is performed at the target. The matching action of a send is a receive (either blocking or non-blocking), and similarly, the matching action of a receive is a send (either blocking or non-blocking). nnAt the start of each timestep, each processor that is not blocked starts to run its next instruction. Processors that execute blocking instructions become blocked. Messages can be received at the end of the timestep in which they are sent, but may need to wait several timesteps until the recipient performs a matching receive. If the recipient of a message is waiting to receive from the sender, then the message is received in the same timestep. Messages are received in the order that they are sent. If all of the actions for a particular blocking instruction complete at the end of the timestep, then the processor that ran the instruction will be unblocked before the next timestep. nnA correct program will terminate only when all of its actions have completed. Pending non-blocking operations must be completed before a program can terminate. nnYour program will take in a list of processors and actions (no more than 100 for each processor), and determine if each processor finishes its program. If a given processor does not finish, it must print out which other processors are preventing it from finishing.nInputnnThe first line will be a single positive integer that tells how many processors will be listed. For each processor there will be one line containing the name of the processor (a single capital letter) followed by a positive integer, N . The following N lines will contain the instructions that comprise the program for that processor. nnAn instruction is of the form ``Mode Action Target(s)'' where ``Mode'' can be ``B'' or ``N'', for blocking or non-blocking, respectively. ``Action'' can be ``S'' or ``R'', for send or receive, respectively. ``Target(s)'' will be one or more processor names to which the action is to be addressed. No processor will be listed twice and a processor will never attempt any sort of communication with itself . A send to multiple targets will not complete until matching receives have been performed by all of the targets (and vice versa).nOutputnnGiven that instruction 1 occurs at t = 1, your program will output at which timestep each processor finishes. If a processor does not finish, you must output which processor are preventing that processor from finishing. Processors should be listed in alphabetical order, both for the list of processors and the sets of processors that prevent a processor from finishing. The list of processors preventing termination should list processors at most once and separate multiple processors with ``and''.nSample Inputnn4nI 5nB S B P CnN S B P CnN R BnB R PnB R CnB 2nB R InB S InP 3nN S InN R InB R InC 4nN S InB R InB S PnB R InSample OutputnnB finishes at t=4nC never finishes because of PnI never finishes because of B and CnP finishes at t=5
死锁Deadlock
updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Deadlock found when trying to get lock; try restarting transactionrnrnrnsql语句:rn update table set money= money+? where id = ?rnrn就这样一个语句,为什么出现死锁呢?整个表没有任何索引,id是主键。rnrn我用的是spring+mybatis+mysql(InnoDB)rn这个方法上有事务注解,应该是并发导致的死锁,我现在没想明白为什么会死锁呢?rn有什么解决办法呢?
Deadlock detection
Deadlock detection method used
APPARENT DEADLOCK!!!
在网上查了半天也没有个答案,所以请各位大侠帮忙解决一下,小弟不胜感激。rn下边是异常的出错信息:rnrncom.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@e8174f -- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks!rnrnjava.sql.SQLException: Connection is invalidrn at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1.refurbishResource(C3P0PooledConnectionPool.java:141)rn at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1.refurbishIdleResource(C3P0PooledConnectionPool.java:105)rn at com.mchange.v2.resourcepool.BasicResourcePool$AsyncTestIdleResourceTask.run(BasicResourcePool.java:1105)rn at java.lang.Thread.run(Thread.java:619)rn谢谢各位大侠
sybase deadlock
在数据库业务高峰的时候经常追踪到异常:rncom.sybase.jdbc3.jdbc.SybSQLException: Your server command (family id #0, process id #1227) encountered a deadlock situation. Please re-run your command.rnrn鄙人在网络上查了大量资料,也问了很多人,还是没搞定,只好自己想了。。rnrn对相关的业务表的相关查询字段已经建了索引,以便加快相关查询速度避免锁竞争,还是老报异常,rn高峰期的时候每秒报200次以上,痛苦。。rnrn接着看了下sybase的文档“Performance and Tuning-Locking.pdf”(在sybase的网站上可以免费下载),rn发现数据库的锁策略和索引的查询效率关系很密切,于是就决定将对应的业务表的锁策略由'allpages'rn改为'datapages',问题解决了,没有再报检测到死锁了。。rnrn表锁的时候即使建了索引,再执行相关的操作的时候索引表也会被锁,但是页锁和行锁有更新的时候是rn即使释放的,不会锁住。。rnrn希望这篇文章对有相关问题的朋友有帮助。。rn
查询数据产生deadlock的问题,急。
下面是一段查询:rn[code=SQL]rnselect aa.Company, aa.MeterBookNumber,aa.CopyUserName,aa.TotalMoney,aa.RemainMoney,aa.cur,rnbb.YearTotalMoney,bb.YearRemainMoney,bb.Yearcurrn from rn(rnselect info.Company,c.MeterBookNumber,c.CopyUserName,TotalMoney=sum(b.TotalMoney),rn RemainMoney=sum(b.RemainMoney),rncur=rncase when sum(b.TotalMoney)=0 then Null rn else convert(decimal(10,2),(1-sum(b.RemainMoney)/sum(b.TotalMoney))*100)endrnfromrnwcCopyMeterPlanEntry c rnleft join wcCopyMeterPlan d on c.PlanID=d.ID rnleft join wcCopyNoteData a on a.MeterBookID=c.MeterBookIDrnleft joinrn(rnselect a.* from rn[color=#FF0000]wcComputeChargeRecord[/color] a inner join wcCopyNoteData b on a.CopyNoteDataID=b.ID rnwhere b.CopyYear=2009 and b.CopyMonth=12rn)rnb on a.ID = b.CopyNoteDataIDrnleft join wcUserBaseInfo info on info.ID=a.CustomerIDrnwhere info.Company='**公司'rnand d.PlanYear=2009 and d.PlanMonth=12rngroup by info.Company,c.CopyUserName,c.MeterBookNumberrn) aa rninner join rn(rnselect info.Company,c.MeterBookNumber,YearTotalMoney=sum(b.TotalMoney),YearRemainMoney=sum(b.RemainMoney),rnYearcur=rncase when sum(b.TotalMoney)=0 then Null rn else convert(decimal(10,2),(1-sum(b.RemainMoney)/sum(b.TotalMoney))*100)endrn from rnwcCopyMeterPlanEntry c rnleft join wcCopyMeterPlan d on c.PlanID=d.ID rnleft join wcCopyNoteData a on a.MeterBookID=c.MeterBookIDrnleft join rn(rn select a.* from [color=#FF0000]wcComputeChargeRecord[/color] a inner join wcCopyNoteData b on a.CopyNoteDataID=b.ID rn where b.CopyYear=2009 and b.CopyMonth<=12rn)rnb on a.ID = b.CopyNoteDataIDrnleft join wcUserBaseInfo info on info.ID=a.CustomerIDrnwhere info.Company='**公司' rnand d.PlanYear=2009 and d.PlanMonth=12 rngroup by info.Company,c.MeterBookNumber rn) bb on aa.MeterBookNumber=bb.MeterBookNumberrn[/code]rnrn查询需要比较长时间,在查询之后,执行此操作:rn[code=SQL]rnupdate [wcComputeChargeRecord] set [PayStateID]='2',[PayState]='585',[RemainWater]=0.0,[RemainMoney]=0.0 where [ID]=3374297rn[/code]rn这个时候形成deadlock,必须等查询完成后,update才生效,rn我对这个的原因不是特别明白,一般的简单查询是不会出现这样的问题的,是不是因为嵌套的原因呢?rn请大虾们指点。
数据库为什么会有deadlock问题
[u]https://dev.mysql.com/doc/refman/5.7/en/innodb-deadlock-example.html[/u]rnrn官方例子中的A需要等待B释放X锁. 然后由于B持有X锁所以A,B必有一个要抛出异常. rnrn通过测试我发现,理论上和A是否获取了S锁无关(我有一个程序全是update行为, 也发生了x锁冲突), 只要A获取了X锁,并且还没释放 或者释放较慢 那么B竞争X锁的行为就会引发一个异常.rnrn但是这么设计会不会太极端了呢? 一般的程序语言内存操作的时候会让A,B,C,D,E处于等待. 而mysql选择让A,B,C,D,E的其中4个抛出异常.rnrn如果换一种设计方式, A,B都继续等待,直到其中一方放开锁. 或者由开发人员设置锁等待的超时时间难道不是更好吗?
一则MySQL deadlock问题的解决
用户反馈服务器日志中出现大量:Deadlock found when trying to get lock; Try restarting transaction message from server: &quot;Lock wait timeout exceeded; try restarting transaction&quot;; 进行了一段时间loadrunner并发测试并在网上找了很多先行者的文章,...
如何解决死锁问题(deadlock)
we are doing a project . rnIn one Save button , we must do much work. rn(1) update a record for table Arn(2) delete a record for table Arn(3) add a new record to table ArnrnAll these action use the one transcation . rnFor example:rn conn.BeginTran rn UpdateRecord.rn DeleteRecordrn AddNewRecord.rn conn.committranrnrnBut when we click the save button at same time useing two different computer, the system will occur deadlock. rnThe Database is SQL Server 7.0 and Develop Tool is VB6.0rnrnIf we get rid of the transcation , the system is ok. rnand if we move the DeleteRecord and AddNew to out of the transcation, the system is ok too. rnBut we can't do like it , because the system must have transcation. rnPlease give you advice, Thank you very much. rnrn
哲学家就餐问题
嵌入式操作系统及其应用——哲学家就餐问题的实验和课件。
哲学家问题代码 C++
这是著名的哲学家问题 C++的可执行代码
哲学家进餐问题
看了就知道,我也不知道该怎么介绍
Linux下哲学家问题的实现
算法的思想是,每个哲学家想要进餐时,先拿左手边的筷子,如果筷子可用就拿起来,不可用就等待,再拿右手边的筷子,如果筷子可用,就拿起筷子,不可用就等待,只有当两个筷子都可用时,哲学家才能进餐。 为了实现这个算法,需要互斥锁和五个条件变量。 pthread_mutex_t mutex; pthread_cond_t chopstick[5]; 另外创建数组sticks[5]表示这五个筷子收否可用,当sticks[i]等于1时,表示筷子i可用,等于0表示这个筷子不可用。
操作系统 哲学家问题
操作系统哲学家问题代码,但最后结果好像稍微有点bug,发生原因不详,有时候重启就好了,怀疑是调试机本身系统问题
哲学家就餐的问题
Exercise 1. 哲学家就餐的问题是由并发先驱E. W. Dijkstra发明的,旨在澄清死锁(dead-lock)和饥饿自由(starvation freedom)的概念。 想象一下五个哲学家,他们终其一生只是在思考和就餐。 他们坐在一张带五把椅子的圆桌旁。 每个位置前面有一大盘米饭。 但是,只有五根筷子(在原文中说的是刀叉)可用,如图1.5所示。 每个哲学家都在思考。 当他饿了,他坐下来...
哲学家就餐问题的代码实现
1.AND型信号量 (1)Chopsticks.java** package philosopy; import java util.*; class Chopsticks { public static List chops = new ArrayList(); static { chops.add(false); //为了方便计算,第一个不会参与计算 chops.add(false); cho...
哲学家进餐问题仿真
哲学家进餐问题仿真 有需要的同学可以下载 可以了解实现的原理
哲学家就餐问题JAVA代码
简单易懂 主要应用闲成方面的知识 class Philosopher extends Thread   {   public Philosopher( DiningPhils HOST , int i )   {     host = HOST;     index = i;   }   public void setTimeSlice( int TS )   {     ts = TS;   }   public void setLeftChopstick( boolean flag )   {     host.setChopstick(index, flag);   }……
相关热词 c#入门推荐书 c# 解码海康数据流 c# xml的遍历循环 c# 取 查看源码没有的 c#解决高并发 委托 c#日期转化为字符串 c# 显示问号 c# 字典对象池 c#5.0 安装程序 c# 分页算法