English 中文(简体)
N Asynchronous相互排斥 校对
原标题:Mutual Exclusion for N Asynchronous Threads

我提出了一刀切的申请,意思是,在任何特定时间都可以发生N事件。 是否有一个已知的算法,可以相互排斥Nthreads,而不必逐条硬化,以备有身份证?

最佳回答

我不认为 Java字本身有点反对,因为 Java字基本上只读了。 你们也许能够找到一个图书馆,或者能够执行,它管理着几条 Java印法的镜子——但是它们是否都在同一个变形空间运行? 他们需要相互交流。

< 假设您的多个座右铭可以共享一个静态的<代码>mutex<>code> 可变式部分,只要您assume <代码>++被视为对正在翻新的系统的一种原子操作,如何做到这一点?

int mutex = 0;
mutuallyExclusiveOperation(){
  succeed=false;
  while(!succeed){
    while(mutex>0){ sleep();  }
    m=mutex++;   //"Simultaneously" read and increment
    if(m>0)mutex--;
    else{
      doMutuallyExclusiveThing();
      succeed=true;
      mutex--;
    }
 }
}
问题回答

贾瓦文一般是单一阅读的,因此你从未有两部同时修改同一数据的法典。 你们可以在使用网络工人的现代浏览器中使用多个线索,但他们只能通过传递信息,而不是分享记忆来进行沟通,因此,如果你重新使用网络工人,你就不必担心相互排斥。

如果某些用户行动正在使用我们想要避免的多个线索(针对美国宇宙航空研究开发机构的请求),那么,可以单独阅读,但有时会出现问题。 如果我们想要 make,我们就可以使用一个全球变量。 不管怎样,我确信,这样做是站不住脚的——我不知道有什么更好的解决办法,因为我不参与这么多的书面陈述。

希望在某些简单的情况下有助于你:

<html>

 <head>
  <script type="text/javascript">
        var magic_global;
        magic_global = true;

        function magic_switch() {
                magic_global = !magic_global;
        }
  </script>
 </head>

 <body>
        <a href="#" onclick="magic_switch();">switch Magic</a>
        <a href="#" onclick="alert(magic_global);">show the Magic</a>
 </body>

</html>




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签