草庐IT

async-redux

全部标签

c++ - boost async_write 问题

我将展示一些代码;voidwh(constboost::system::error_code&ec,std::size_tbytes_transferred){std::cout当我使用该代码时出现内存泄漏,我发现一些代码(如minicom_client教程)甚至从该代码中变得复杂,而且我在minicom_client上出现内存泄漏。如果我使用boost::asio::write(pSerial,boost::asio::buffer("A",1));代替async_write效果很好,你能解释一下那里发生了什么吗,非常感谢...... 最佳答案

如何在此Redux还原器中正确更新状态

我有一个动作,可以返回包含过滤对象的有效载荷。我希望将此对象作为新状态或我向用户展示的状态返回。我谈论的具体情况在以下代码中显示:casePaginate_BLOGreturn{...state,action.payload.data};我的博客还原器的完整代码:import{FETCH_POSTS,FETCH_POST,DELETE_POST,PAGINATE_BLOG}from'../actions';import_from'lodash';exportdefaultfunction(state={},action){switch(action.type){caseFETCH_POST:c

为什么在更新存储后,组件不会更改(React-Redux)

我有一个component,更新后不会更改数据storeclassRenderCommentsextendsComponent{commentsParse(){returnthis.props.comments.map((comment)=>{if(comment.hasComments===true){return()//return}});//this.props.comments.map()}//commentParserender(){return({this.commentsParse()})//return}//render}//RenderCommentsfunctionmapS

c++ - std::async 不并行化任务

在此代码段中使用C++11std::async:intfoo(){::sleep(2);return123;}intmain(){futurer1(async(foo));intr2=foo();cout它产生正确的结果,但连续运行两个foo(整个应用程序运行4秒)。编译为:g++-std=gnu++11-O2foo.cc-lpthread(Ubuntu12.1064位,gcc4.7.2) 最佳答案 您可能需要添加launchpolicystd::launch::async的:std::async(std::launch::asyn

c++ - std::async 超时

有没有办法在std::async方法中实现超时,所以如果线程在指定的时间内没有完成,我希望这个调用超时并完成。我该如何实现此功能。 最佳答案 没有(标准的)方法可以进入线程并杀死它,无论如何这通常不是一个好主意。更简洁的选择是将开始时间和最长持续时间传递给函数,然后(可能随着计算的进行多次)检查当前时间减去开始时间是否太长。我会做这样的事情:#includetemplateclasstimeout{public:typedefClockclock_type;typedeftypenameclock_type::time_pointt

c++ - std::async 在指定 launch::async 时不执行

也许我错过了C++11中新std::async的正确用法,但是这个声明(在cppreference.com结束):Iftheasyncflagisset(i.e.policy&std::launch::async!=0),thenasyncexecutesthefunctionfonaseparatethreadofexecutionasifspawnedbystd::thread(f,args...),exceptthatifthefunctionfreturnsavalueorthrowsanexception,itisstoredinthesharedstateaccessibl

c++ - 使用 std::async 调用模板函数的正确方法是什么

我正在尝试了解std::async的用途。我在下面编写了模板函数来将所有条目累积到一个整数数组中。template::value>::type>Tparallel_sum(T(&arr)[N],size_tstart=0,size_tend=N-1){if(end-start,arr,start,mid);autores2=parallel_sum(arr,mid+1,end);returnres2+res1.get();}}当我在main中调用上面的函数时,出现以下编译错误(以及更多错误):errorC2672:'std::async':nomatchingoverloadedfun

c++ - 使用 Xcode 为 macOS 构建时,C++ async 是否使用线程池?

使用平台的标准开发工具和编译器[1],std::async是否为每个后台作业生成一个新的操作系统线程,或者它是否使用线程池或一些基于工作窃取任务队列?Xcode、Clang/LLVM 最佳答案 使用平台标准工具链(Xcode/Clang)构建的应用程序不使用线程池。使用std::async启动的任务的堆栈底部包含std::thread和pthread调用。退出时,每个作业调用pthread_exit()杀死运行它的线程。在为iOS构建时,Xcode8.3.3还在每个使用std::async启动的作业中使用一个操作系统线程(在原始iP

c++ - 将函数直接传递给 std::async 和使用 std::bind 有什么区别?

我最近开始向我正在处理的库添加异步支持,但我遇到了一个小问题。我从这样的事情开始(稍后会有完整的上下文):returnexecuteRequest(false,d,&callback,false);那是在添加异步支持之前。我试图将其更改为:returnstd::async(std::launch::async,&X::executeRequest,this,false,d,&callback,false);但是编译失败。MCVE:#include#includeintcallback(constint&t){std::coutTexecuteRequest(boolmethod,Req

c++ - boost ASIO async_read_some

我在实现一个简单的TCP服务器时遇到了困难。以下代码摘自boost::asioexamples,准确地说是“Http服务器1”。voidconnection::start(){socket_.async_read_some(boost::asio::buffer(buffer_),boost::bind(&connection::handle_read,shared_from_this(),boost::asio::placeholders::error,boost::asio::placeholders::bytes_transferred));}voidconnection::ha