我们正在测试嵌入式ruby的线程合作.我们有一个C ruby扩展实现了以下方法
1. longRunningMethod()
2. shortRunningMethod().
Run Code Online (Sandbox Code Playgroud)
这是检查线程协作的代码
//文件test.rb
require 'mymodule'
$a = 0;
obj = MyModule::MyClass.new
t1 = Thread.new{$a = obj.veryLongRunningOperation(); puts "doneLong"}
sleep 1
$a = obj.shortOperation()
puts "doneShort"
t1.join
Run Code Online (Sandbox Code Playgroud)
我们已经确保longRunningMethod使用嵌套for循环执行需要超过1秒(5秒)根据我们的理解,应首先完成shortRunningMethod然后再使用longRunningMethod.
但是,只有当我们没有任何睡眠命令时才会观察到这一点.但是当我们介绍"睡眠1"声明时.首先执行longRunningMethod,然后执行shortRunningMethod
任何人都会给我们指出为什么sleep语句产生这个结果?
[我们正在使用ruby 1.8.6]先谢谢.
我有一个从ruby脚本调用的变量参数函数,如下所示:
static myMethod(VALUE exc, const char *fmt, ...)
{
// Implementation of myMethod which requires all the arguments
// how to access the all arguments.
}
Run Code Online (Sandbox Code Playgroud)
谁能告诉我如何访问所有参数.提前致谢.
我必须延长当前线程的执行时间超过1秒.我可以在c ++中使用什么?
我可以使用delay()或其他什么?
[来自评论]:让我解释一下场景:我有一个主线程(LONG)启动另一个子线程(SHORT),所以我需要保持执行LONG线程,以便它在执行SHORT后结束. - Prajkata 4分钟前