Redian新闻
>
How to ensure atomic execution of lines
avatar
How to ensure atomic execution of lines# Unix - 噫吁兮,危乎高哉
z*g
1
Consider this case,
....;
....;
p(semaphore);//Entering waiting state
How can I make sure the last line is executed immediately after preceding
lines?
Sometimes, OS will preempt the program just before the p(..) is executed and
resume the program later. This may cause bad race condition.
I appreciate any clues for solving this problem. Thanks a lot.
avatar
x*g
2
I tend to think for a users mode app, there is no chance for you to
do this. Otherwise every user has the potential of locking up the
whole system.
If you can shorten your code and make sure they can be finished within
1 timeslice, you will very less likly be preempted.

【在 z****g 的大作中提到】
: Consider this case,
: ....;
: ....;
: p(semaphore);//Entering waiting state
: How can I make sure the last line is executed immediately after preceding
: lines?
: Sometimes, OS will preempt the program just before the p(..) is executed and
: resume the program later. This may cause bad race condition.
: I appreciate any clues for solving this problem. Thanks a lot.

avatar
c*t
3

Huh? That means your code is not protected for critical conditions.
Re-write your code.

【在 z****g 的大作中提到】
: Consider this case,
: ....;
: ....;
: p(semaphore);//Entering waiting state
: How can I make sure the last line is executed immediately after preceding
: lines?
: Sometimes, OS will preempt the program just before the p(..) is executed and
: resume the program later. This may cause bad race condition.
: I appreciate any clues for solving this problem. Thanks a lot.

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。