UNIX便携式原子操作 [英] UNIX Portable Atomic Operations

查看:191
本文介绍了UNIX便携式原子操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有C语言为原子变量的操作类似于使用pthread的便携式线程?

A(POSIX-)移植的方法

原子操作就像被自动执行,这意味着,没有上下文切换可通过操作干扰增量并获得操作。在Linux内核空间,我们必须 atomic_t 类型,在Java中我们有<一个href=\"http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/atomic/package-summary.html\">java.util.concurrent.atomic包。

在Linux中,atomic.h中文件提供原子操作,但包括依赖于平台例如的#include&LT; ASM-x86_64的/ atomic.h中方式&gt; ,这是不是可以在Mac OS X上类似的方式


解决方案

对于任何人谁在将来在此跌倒,C11原子公司都做到这一点的最好办法了 - 我相信他们将被包括在GCC 4.9

Is there a (POSIX-)portable way in C for atomic variable operations similar to a portable threading with pthread?

Atomic operations are operations like "increment and get" that are executed atomically that means that no context switch can interfere with the operation. In Linux kernel space, we have to atomic_t type, in Java we have the java.util.concurrent.atomic package.

On Linux, the atomic.h file provides atomic operations, but the include is platform dependent e.g. #include <asm-x86_64/atomic.h> and it is not available on Mac OS X in a similar way.

解决方案

For anyone who stumbles upon this in the future, C11 atomics are the best way to do this now - I believe they will be included in GCC 4.9.

这篇关于UNIX便携式原子操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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