10.10 Execution order

本文主要介绍了C#程序中线程的执行顺序。执行时要在关键执行点保留各执行线程的副作用,包括对易失字段的读写等。实现可改变执行顺序,但需遵循数据依赖、初始化顺序规则等约束条件。异步事件中断时,原程序顺序的可观察副作用未必可见。
10.10 Execution order
Execution shall proceed such that the side effects of each executing thread
are preserved at critical execution
points. A side effect is defined as a read or write of a volatile field, a
write to a non-volatile variable, a write
to an external resource, and the throwing of an exception. The critical
execution points at which the order of
these side effects must be preserved are references to volatile fields (?7.4
.3), lock statements (?5.12), and
thread creation and termination. An implementation is free to change the
order of execution of a
C# program, subject to the following constraints:
?Data dependence is preserved within a thread of execution. That is, the
value of each variable is
computed as if all statements in the thread were executed in original
program order.
?Initialization ordering rules are preserved (?7.4.4 and ?7.4.5).
?The ordering of side effects is preserved with respect to volatile reads
and writes (?7.4.3). Additionally,
an implementation need not evaluate part of an expression if it can deduce
that that expression.s value is
not used and that no needed side effects are produced (including any caused
by calling a method or
accessing a volatile field). When program execution is interrupted by an
asynchronous event (such as an
exception thrown by another thread), it is not guaranteed that the
observable side effects are visible in
the original program order.
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值