相关疑难解决方法(0)

使用Thread.Abort()有什么问题

所以我知道你不应该使用

Thread.Abort()
Run Code Online (Sandbox Code Playgroud)

但我从未得到过很好的解释.是否存在性能损失或隐藏的问题?

我知道你不能忽略/吞下ThreadAbortException(这是有道理的)

.net c# multithreading

62
推荐指数
5
解决办法
3万
查看次数

为什么Thread.stop()如此危险

为什么Thread.stop()这么危险?

为什么建议使用Thread.interrupted()

我知道stop已被弃用.还有什么东西让它不安全?

有什么地方可以使用stop方法吗?如果是这样给我一个例子.

java multithreading

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

超时后中止 Rust 中的评估

我有一个 Rust 函数(不是我写的),它要么以毫秒为单位返回,要么在失败前等待约 10 分钟。

我想将对这个函数的调用包装在一个函数中,如果运行时间超过 10 秒,则返回一个Optionwhich is None,如果运行时间较短,则包含结果。然而,我还没有找到任何方法来中断这个函数被调用后的评估。

例如:

// This is the unpredictable function
fn f() {
    // Wait randomly for between 0 and 10 seconds
    let mut rng = rand::thread_rng();
    std::thread::sleep(std::time::Duration::from_secs(rng.gen_range(0, 10)));
}

fn main() {
    for _ in 0..100 {
        // Run f() here but so that the whole loop takes no more than 100 seconds
        // by aborting f() if it takes longer than 1 second
    }
}
Run Code Online (Sandbox Code Playgroud)

我发现了一些可以使用带有超时的 future 的方法,但我想最大程度地减少开销,而且我不确定为该函数的每次调用创建一个 …

timeout rust

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

有没有办法在给定的时间后使单元/集成测试失败?

我正在 Rust 中实现一个虚拟机作为练习。一些集成测试在该虚拟机上运行小程序并对最终结果做出断言。

但是,可能会发生错误导致机器陷入无限循环,这意味着cargo test永远不会完成。

有没有办法在给定的时间后使单元/集成测试失败?也许类似于#[should_panic],但相反,说,#[time_limit(500)]

testing unit-testing rust

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

标签 统计

multithreading ×2

rust ×2

.net ×1

c# ×1

java ×1

testing ×1

timeout ×1

unit-testing ×1