Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Multithreading Julia的非阻塞读取_Multithreading_Io_Julia_Getch - Fatal编程技术网

Multithreading Julia的非阻塞读取

Multithreading Julia的非阻塞读取,multithreading,io,julia,getch,Multithreading,Io,Julia,Getch,我希望在不阻塞主线程的情况下读取用户输入,就像conio.h中的getch()函数一样。朱莉娅有可能吗 我尝试了@async,但看起来好像我的输入没有被读取,尽管主线程没有被阻塞。我认为问题在于,要么你运行在全局范围上,这使得@async创建了自己的局部变量(当它读取时,它会读入另一个范围内的变量)或者你使用的是茱莉亚的旧版本 以下示例以非阻塞方式从STDIN读取整数 function foo() a = 0 @async a = parse(Int64, readline())

我希望在不阻塞主线程的情况下读取用户输入,就像
conio.h
中的
getch()
函数一样。朱莉娅有可能吗


我尝试了
@async
,但看起来好像我的输入没有被读取,尽管主线程没有被阻塞。

我认为问题在于,要么你运行在全局范围上,这使得
@async
创建了自己的局部变量(当它读取时,它会读入另一个范围内的变量)或者你使用的是茱莉亚的旧版本

以下示例以非阻塞方式从
STDIN
读取整数

function foo()
    a = 0
    @async a = parse(Int64, readline())
    println("See, it is not blocking!")
    while (a == 0)
        print("")
    end
    println(a)
end
以下两个示例使用数组在全局范围内完成此工作。您可以对其他类型的可变对象执行相同的操作。 阵列示例:

function nonblocking_readInt()
    arr = [0]
    @async arr[1] = parse(Int64, readline())
    arr
end

r = nonblocking_readInt() # is an array
println("See, it is not blocking!")
while(r[1] == 0) # sentinel value check
    print("")
end
println(r[1])
read(STDIN,Char)
?()@FelipeLema
read(STDIN,Char)
仍然需要一个“enter”来理解输入。我正在寻找类似于
getch()
的东西,因为发生了很多事情,我无法阻止等待输入的执行