草庐IT

dispatch_barrier_async

全部标签

c++ - 以不同方式分派(dispatch)右值和左值并使用 sfinae 禁用一个选项

我想实现一个函数drop_if.给定一个一元谓词和一个顺序容器,它返回一个相同类型的容器,其中仅包含原始元素中不满足谓词的元素。如果输入容器是右值,它应该就地工作,否则创建一个拷贝。这是通过调度到namespaceinternal中的适当版本来实现的。.如果value_type应该禁用r值版本容器的名称不能被覆盖-如std::pair例如-即使容器是右值。以下代码worksasexpected使用clang和当前版本的gcc(>=6.3)。#include#include#include#include#include#includenamespaceinternal{template

c++ - Visual Studio 2012 更新 2 中的 std::async 衰减(丢失)右值引用。任何解决方法?

考虑下面的代码:#include#includeusingnamespacestd;templatevoidTest2(futuref,Workw){async([](future&&f,Workw){},move(f),move(w));}intmain(){futurex=std::async([]()->int{std::this_thread::sleep_for(std::chrono::microseconds(200));return10;});Test2(std::move(x),[](intx){});return0;}以上,由于以下编译器错误而失败:Error1er

kotlin - 如何将 Kotlin 从 1.2 迁移到 Kotlin 1.3.0,然后在演示者函数中使用 async、UI 和 bg

我在Kotlin项目中使用MVP模式。我有一个Presenter类:importcom.google.gson.Gsonimportkotlinx.coroutines.experimental.android.UIimportkotlinx.coroutines.experimental.asyncimportorg.jetbrains.anko.coroutines.experimental.bgclassTeamsPresenter(privatevalview:TeamsView,privatevalapiRepository:ApiRepository,privatevalg

kotlin - 如何将 Kotlin 从 1.2 迁移到 Kotlin 1.3.0,然后在演示者函数中使用 async、UI 和 bg

我在Kotlin项目中使用MVP模式。我有一个Presenter类:importcom.google.gson.Gsonimportkotlinx.coroutines.experimental.android.UIimportkotlinx.coroutines.experimental.asyncimportorg.jetbrains.anko.coroutines.experimental.bgclassTeamsPresenter(privatevalview:TeamsView,privatevalapiRepository:ApiRepository,privatevalg

Equals() 的 C++ 双重分派(dispatch)

假设我有abstractbaseclassShape,与派生类Circle和Rectangle.classShape{};classCircle:publicShape{};classRectangle:publicShape{};我需要确定两个形状是否相等,假设我有两个Shape*指针。(这是因为我有两个vector的实例,我想看看它们是否具有相同的形状。)推荐的方法是doubledispatch.我想出的是这个(这里大大简化了,所以形状等于所有其他相同类型的形状):classShape{public:virtualboolequals(Shape*other_shape)=0;pr

c++ - std::async 使用绑定(bind)到 lambda 的右值引用

我正在尝试使用std::bind将右值引用绑定(bind)到lambda,但是当我将其放入std::async调用时出现问题:(source)autolambda=[](std::string&&message){std::cout这会发出一个编译器错误,我不确定如何解释:error:notypenamed'type'in'classstd::result_of(std::basic_string)>&()>'这是怎么回事?有趣的是,稍作修改就可以按预期编译和工作。如果我将std::string{"helloworld"}更改为c字符串文字,一切正常:(source)autolambd

c++ - C++ 示例 "Memory barrier"

这个问题在这里已经有了答案:C++MemoryBarriersforAtomics(2个答案)关闭9年前。我正在阅读这个关于volatile关键字的问题的答案:https://stackoverflow.com/a/2485177/997112那个人说:Thesolutiontopreventingreorderingistouseamemorybarrier,whichindicatesbothtothecompilerandtheCPUthatnomemoryaccessmaybereorderedacrossthispoint.Placingsuchbarriersaroundo

c++ - std::async 使用同一个线程,我的代码没有实现并行。

我在MacOSXcode4.3.2上使用C++11std::async使用同一个线程,我的代码没有实现并行。在下面的示例代码中,我想创建10个新线程。在每个线程中,我想计算输入变量的平方根并将结果设置为promise。在main函数中,我想显示从线程计算的结果。我正在使用策略launch::async调用std::async,所以我希望它创建一个新线程(10次)。#include#include#include#include#include#includeusingnamespacestd;mutexiomutex;voidfoo(inti,promise&&prms){this_t

C++ 低延迟设计 : Function Dispatch v/s CRTP for Factory implementation

作为系统设计的一部分,我们需要实现工厂模式。结合工厂模式,我们还使用CRTP来提供一组基本功能,然后可以由派生类进行自定义。示例代码如下:classFactoryInterface{public:virtualvoiddoX()=0;};//forceallderivedclassestoimplementcustom_X_impltemplateclassCRTP:publicBase{public:voiddoX(){//docommonprocessing.....thenstatic_cast(this)->custom_X_impl();}};classDerived:pub

c++ - omp 临界区后是否存在隐式 Barrier

在omp临界区之后是否存在隐式omp屏障例如,我可以将以下代码版本1修改为版本2吗?版本-1intmin=100;#pragmaompparallel{intlocalmin=min;#pragmaompforschedule(static)for(inti=0;i版本2intmin=100;#pragmaompparallel{intlocalmin=min;#pragmaompforschedule(static)nowaitfor(inti=0;i版本1和版本2会得到相同的结果吗?omp临界区后是否存在隐式屏障?编辑:如果这个例子很差,我很抱歉。另外,我想知道版本1和版本2之间是