由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
CS版 - help prove the following code correctness?
相关主题
为什么多个线程生成的随机数是一样的?准备100个包子求大神帮下忙 or up to 50刀 (转载)
anyone familiar with z notation?英语Vista
very upset..SE is pretty difficult area请教个VBA问题 (转载)
Re: 请教一个 graph connectivity 的问题questions about a NP-hard problem
c++ type conversion 方面的问题An interview question, what is the answer?
询问一个Big O notation的问题[合集] EE challenge CS
求问时间复杂度a basic big-oh problem
请问各位达人,csp和z notation的区别和利弊。[合集] destro爱CS - episode 1 (EE chanllenge CS)
相关话题的讨论汇总
话题: loaned话题: following
进入CS版参与讨论
1 (共1页)
c******n
发帖数: 4965
1
the basic framework of a connection pool code,
we modified it several times, now it seems to work fine, but I want to make
sure it's really correct
the greatly simplified version looks like the following.
n_loaned is actually an AtomicInteger, I use the "++" notation for
easier reading.
let's say we have 10 threads sharing the same pool obj, they all run the
sequence
"borrowConnection();
// do something for a while ;
releaseConnection()
"
the question is
is it possible that all of them (or any of them) would be blocking on the
line "block_forever()" ??, it seems impossible, but it's difficult to give
a formal proof given multi-threads.
class pool {
n_loaned = 0;
public Connection borrowConnection() {
if ( n_loaned == 10 )
block_forever();

n_loaned++;
}
public void releaseConnection(conn) {
n_loaned--;
}
}
1 (共1页)
进入CS版参与讨论
相关主题
[合集] destro爱CS - episode 1 (EE chanllenge CS)c++ type conversion 方面的问题
Re: for help on mmap for stdout (转载)询问一个Big O notation的问题
c不用thread,如何写“按任意键退出”?求问时间复杂度
cs master请教职业方向定位,有包子请问各位达人,csp和z notation的区别和利弊。
为什么多个线程生成的随机数是一样的?准备100个包子求大神帮下忙 or up to 50刀 (转载)
anyone familiar with z notation?英语Vista
very upset..SE is pretty difficult area请教个VBA问题 (转载)
Re: 请教一个 graph connectivity 的问题questions about a NP-hard problem
相关话题的讨论汇总
话题: loaned话题: following