我在理解AttachedToParent
参数如何工作时遇到了问题.
以下是示例代码:
public static void Main(string[] args)
{
Task<int[]> parentTask = Task.Run(()=>
{
int[] results = new int[3];
Task t1 = new Task(() => { Thread.Sleep(3000); results[0] = 0; }, TaskCreationOptions.AttachedToParent);
Task t2 = new Task(() => { Thread.Sleep(3000); results[1] = 1; }, TaskCreationOptions.AttachedToParent);
Task t3 = new Task(() => { Thread.Sleep(3000); results[2] = 2; }, TaskCreationOptions.AttachedToParent);
t1.Start();
t2.Start();
t3.Start();
return results;
});
Task finalTask = parentTask.ContinueWith(parent =>
{
foreach (int result in parent.Result)
{
Console.WriteLine(result);
}
}); …
Run Code Online (Sandbox Code Playgroud) 当我偶然发现一些非常有趣的东西时,我正在测试我的一些Ruby 1.9代码.我希望有人可以解释为什么会这样.
这是代码:
inf = Float::INFINITY
x = inf - inf
y = 0.0/0.0
puts "X is #{x}"
puts "Y is #{y}"
puts "X and Y are both NaN." if x.nan? && y.nan?
puts "This is all as we expected, but here is the mystery..."
puts "X is not equal to Y." if x == y
puts "Surprisingly not even X is equal to X." if x == x
Run Code Online (Sandbox Code Playgroud)
这是输出:
X is NaN
Y is NaN
X and Y are …
Run Code Online (Sandbox Code Playgroud)