共享数据问题 [英] Shared Data Problem

查看:62
本文介绍了共享数据问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为上一篇文章道歉;让话题出错了。


解决共享数据的最佳方法当前的想法是什么?b $ b问题即以非原子方式访问共享变量如果中断服务程序也改变它可以给出错误的结果

发生在访问的一部分。

-

Ian Bell

Apologies for the last post; got the topic wrong.

What is the current thinking on the best way to solve the shared data
problem i.e. accesssing a shared variable in a non atomic way can give
erroneous results if an interrupt service routine that also changes it
occurs part way through the access.
--
Ian Bell

推荐答案

Ian Bell< ru ********* @ yahoo.com>潦草地写道:
Ian Bell <ru*********@yahoo.com> scribbled the following:
最后一篇文章道歉;弄错了主题。
目前关于解决共享数据的最佳方法的想法是什么问题,即以非原子方式访问共享变量可能会给出错误的结果,如果中断服务例程也会改变它
发生在访问的一部分。
Apologies for the last post; got the topic wrong. What is the current thinking on the best way to solve the shared data
problem i.e. accesssing a shared variable in a non atomic way can give
erroneous results if an interrupt service routine that also changes it
occurs part way through the access.




C标准没有指定关于共享数据或中断的任何内容

服务无论是。就C标准而言,C程序在完全隔离世界其他地方的情况下运行
。请在

新闻组中询问您自己的实施情况。


-

/ - Joona Palaste(pa *** **@cc.helsinki.fi)-------------芬兰-------- \

\ ------- -------------------------------------------------规则! -------- /

我希望我们认识的人会死,所以我们可以给他们留下鲜花。

- 一个6岁的孩子女孩,在墓地里看到鲜花



The C standard doesn''t specify anything about shared data or interrupt
services either. As far as the C standard is concerned, a C program runs
in completer isolation from the rest of the world. Please ask in a
newsgroup about your own implementation.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"I wish someone we knew would die so we could leave them flowers."
- A 6-year-old girl, upon seeing flowers in a cemetery


2005年3月19日星期六17:31:58 +0000,Ian Bell

< ru *********@yahoo.com>写道:
On Sat, 19 Mar 2005 17:31:58 +0000, Ian Bell
<ru*********@yahoo.com> wrote:
为上一篇文章道歉;让话题出错了。

目前关于解决共享数据问题的最佳方法是什么?即以非原子方式访问共享变量可能会给出错误的结果如果一个中断服务程序也改变它
发生在访问的一部分。
Apologies for the last post; got the topic wrong.

What is the current thinking on the best way to solve the shared data
problem i.e. accesssing a shared variable in a non atomic way can give
erroneous results if an interrupt service routine that also changes it
occurs part way through the access.




标准C也不知道关于中断例程的任何事情,但是

你越来越近了,因为它确实知道了不正确的信号,这可能是异步的b $ b。


我怀疑你是什么正在寻找的是''volatile''关键字,即

,每次访问变量时必须重新读取该变量,以防它自从b
以来发生了变化上次。然而,唯一的类型是

保证在C中真正原子(从某种意义上说,没有其他代码

可以在另一个中间访问它access)是char,它被定义为
作为最小的可寻址元素。在实践中,大多数平台都会将b $视为原子,但你真的需要查看你的

特定硬件。


对于其他任何事情,使用volatile char作为锁,并使用volatile for

任何其他共享区域根据先前值禁用优化。

这将减慢它的速度,当然,所以请将这些访问保持在最低限度。

这是一个值得关注的问题。


或者,在极端情况下,使用特定于系统的结构来禁用中断

(如果可以,则为特定中断)对访问进行四舍五入。例如,您可以使用内联汇编程序来执行此操作(但是将其包装在

a头文件中的宏中,以便可以替换它进行移植)。


Chris C



Standard C doesn''t know anything about interrupt routines either, but
you''re getting closer because it does know anout signals, which may be
asynchronous.

I suspect what you are looking for is the ''volatile'' keyword, that says
that the variable must be re-read every time it is accessed in case it
has changed since the last time. However, the only type which is
guaranteed to be truly ''atomic'' in C (in the sense that no other code
can access it in the middle of another access) is char, which is defined
as the smallest addressable element. In practice, most platforms will
probably treat int as atomic, but you really need to look at your
specific hardware.

For anything else, use a volatile char as a lock and use volatile for
any other shared area to disable optimisations based on prior values.
That will slow it down, of course, so keep such accesses to a minimum if
that''s a concern.

Or, in the extreme, use system-specific constructs to disable interrupts
(the specific interrupt if you can) round the accesses. You may be able
to do that with inline assembler, for instance (but wrap it in macros in
a header file so it can be replaced for porting).

Chris C


Joona I Palaste写道:
Joona I Palaste wrote:

C标准没有任何关于共享数据或中断服务的说明。就C标准而言,C程序与世界其他地方完全隔离。请在
新闻组中询问您自己的实现。

The C standard doesn''t specify anything about shared data or interrupt
services either. As far as the C standard is concerned, a C program runs
in completer isolation from the rest of the world. Please ask in a
newsgroup about your own implementation.




这是一个关于C或C标准的新闻组吗?标准不提供b $ b b提及申请,但这里一直在讨论。


Ian


-

Ian Bell



Is this a newsgroup about C or the C standard?? The standard does not
mention applications but they are discussed here all the time.

Ian

--
Ian Bell


这篇关于共享数据问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆