Mutex的正确语法是什么

时间:2021-09-30 15:23:46

I can not figure out what is wrong with the following but I keep getting syntax errors for the closing "}" brace. I was under the assumption that this was the proper syntax for Mutex based on http://www.ruby-doc.org/core-2.0.0/Mutex.html

我无法弄清楚以下内容有什么问题,但我一直在收到关闭“}”大括号的语法错误。我假设这是基于http://www.ruby-doc.org/core-2.0.0/Mutex.html的Mutex的正确语法。

  semaphore = Mutex.new 

  semaphore.synchronize {
    r_failure.push( username )
    thread_count--
  }

1 个解决方案

#1


1  

Your problem has nothing to do with Mutex. The problem is:

你的问题与Mutex无关。问题是:

thread_count--

You cannot use - in a variable name or a method (unless doing it in a special, unusual way).

你不能在变量名或方法中使用 - 除非以特殊的,不寻常的方式进行。

#1


1  

Your problem has nothing to do with Mutex. The problem is:

你的问题与Mutex无关。问题是:

thread_count--

You cannot use - in a variable name or a method (unless doing it in a special, unusual way).

你不能在变量名或方法中使用 - 除非以特殊的,不寻常的方式进行。