小编New*_*wyo的帖子

notifyAll()抛出IllegalMonitorStateException

我正在设计两个线程:一个必须获取播放器的名称,第二个线程必须等待设置的名称才能继续,但第一个线程中的notify()all抛出了IllegalMonitorStateException错误.

private NameFecth nameFetch;
private UseName useName;
private Object nameSetLock; 
public static void method{
   nameSetLock = new Object()
   nameFetch = new NameFetch(nameSetLock);
   useName = new UseName(nameSetLock);
   Thread nameFetchThread = new Thread(nameFetch);
   nameFetchThread.start();
   Thread useNameThread = new Thread(useName);
   useNameThread.start();
}

public class NameFetch implements Runnable{
    /*variables and constructers*/

    public void run(){
       /*get name and set the variable somehow*/
       synchronized(nameSetLock){
         notifyAll();
       }
    }
}

public class UseName implements Runnable{
    /*variables and constructers*/

   public void run(){
     while(!nameBeenSet){
       synchronized(nameSetLock){
         try{
           wait();
         }catch(InterruptedException e) {} …
Run Code Online (Sandbox Code Playgroud)

java concurrency multithreading

5
推荐指数
1
解决办法
6219
查看次数

getchar()函数不起作用

#include <stdio.h>

int main(int argc, const char * argv[])
{
    long nc;

    nc=0;
    while (getchar()!=EOF) {
        ++nc;
        printf("%ld\n", nc);
    }
}
Run Code Online (Sandbox Code Playgroud)

这是代码,当我输入一个字符时,它将打印1然后打印2,即使我只键入一次.

我正在使用Xcode.

c xcode

1
推荐指数
1
解决办法
1456
查看次数

ARM汇编DCD坏指令

我正在使用 yagarto 的 arm-none-eabi 来编译汇编代码,但它给出了消息

Error: bad instruction `a DCD 1,2,3'
Run Code Online (Sandbox Code Playgroud)

当我使用 DCD 指令时

使用不合法吗?如果没有,我如何为 ARM 中的数据保留内存空间?

谢谢

assembly arm

1
推荐指数
1
解决办法
3301
查看次数

标签 统计

arm ×1

assembly ×1

c ×1

concurrency ×1

java ×1

multithreading ×1

xcode ×1