Linux上的gcc等同于微软的关键部分是什么? [英] What are gcc on linux's equivalent to microsoft's critical sections?

查看:201
本文介绍了Linux上的gcc等同于微软的关键部分是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Microsoft Visual C ++编译器具有 EnterCriticalSection ExitCriticalSection
对象以允许线程之间的同步。



什么是GCC相当于?



我看到 __ sync_synchronize 以及 __ scoped_lock



事实上,我看到提到了一些原子函数以及
__ atomic 个数。

<我真的一直在使用 __ sync_fetch_and_add 作为我的原子增量
我应该使用 __ atomic_add_dispatch 来代替吗?<
有什么区别?



我应该使用哪一种?是否有一些C ++中的结构可用于最新版本的GCC和Visual C ++ 2010中,这些结构可用于编写一些跨平台代码。



<我看到boost有一些可用的功能,但由于各种原因,我不允许在windows下使用boost。

在Linux(和其他Unixen)上,您需要使用PThreads或Posix Threads。在Windows上没有等同于关键部分;使用Mutex。



编辑:见下面的第一条评论 - 显然Posix互斥体和Win32临界区一样,它们绑定到单个进程。 p>

The Microsoft Visual C++ compilers have the EnterCriticalSection and ExitCriticalSection objects to allow for synchronization between threads.

What is the GCC equivalent?

I see references around to __sync_synchronize along with __scoped_lock

In fact I see mention of a number of atomic __sync functions along with a number of __atomic ones.

I actually have been using __sync_fetch_and_add for my atomic increment Should I be using __atomic_add_dispatch instead?
What's the difference?

Which ones should I be using? Are there some constructs in C++ that I can use in both the latest version of GCC and Visual C++ 2010 that are available as I'm going to be writing some cross platform code.

I see boost has some functions available, but for various reasons I'm not allowed to use boost under windows.

解决方案

On Linux (and other Unixen) you need to use PThreads, or Posix Threads. There is no equivalent to Critical Sections on Windows; use a Mutex instead.

EDIT: See first comment below -- apparently Posix Mutexes are the same as Win32 Critical Sections in that they are bound to a single process.

这篇关于Linux上的gcc等同于微软的关键部分是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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