boost::thread 库在调用join或者detach接口时,会释放系统哪些资源?
#include <boost/thread/thread.hpp>
#include <boost/bind.hpp>
#include <iostream>
#include<boost/function.hpp>
class HelloWorld;
extern void hello_2(boost::shared_ptr<HelloWorld> he);
extern void hello_3();

typedef boost::function<void()> Func_t;


class HelloWorld: public boost::enable_shared_from_this<HelloWorld>
{
public:
 HelloWorld(std::string name):name_(name),b_(name)
 {

         std::cout<<"HelloWorld begin:"<<name_<<std::endl;
         std::cout<<"HelloWorld end:"<<name_<<std::endl;
 }
~HelloWorld()
{
        std::cout<<"~HelloWorld begin:"<<name_<<std::endl;
        //thread_group_.join_all();
        sleep(5);
        std::cout<<"~HelloWorld end:"<<name_<<std::endl;
}
void hello_1()
{
        std::cout <<"Hello_1 world, I''m a thread!"<< std::endl;
        sleep(5);
        std::cout<<"sleep 5s"<<std::endl;
}
 void start()
 {
        //boost::shared_ptr<HelloWorld> data_transmitter_ptr = shared_from_this();
        //boost::shared_ptr<HelloWorld> hello2(new HelloWorld("submain"));  
             //thread_group_.create_thread( boost::bind(&HelloWorld::hello_1, data_transmitter_ptr) );//进不了HelloWorld析构
            //thread_group_.join_all();//可进入HelloWorld析构
        //thread_group_.create_thread( boost::bind(&hello_2,hello2) );//可进入HelloWorld析构
        //thread_group_.create_thread( boost::bind(&hello_2,data_transmitter_ptr) );//不可进入析构HelloWorld析构
        //thread_group_.create_thread( boost::bind(&hello_3) );//可以进入HelloWorld析构

 }
 boost::thread_group thread_group_;
 std::string name_;
};
void hello_2(boost::shared_ptr<HelloWorld> he)
{
        //boost::shared_ptr<HelloWorld> hello2(new HelloWorld());
        std::cout <<"Hello_2 world, I''m a thread begin!"<< std::endl;
        std::cout <<"Hello_2 world, I''m a thread end!"<< std::endl;
}
void hello_3()
{
        //boost::shared_ptr<HelloWorld> hello2(new HelloWorld());
        std::cout <<"Hello_2 world, I''m a thread!"<< std::endl;
}
int main(int argc, char* argv[])
{
        {
                boost::shared_ptr<HelloWorld> hello(new HelloWorld("main"));
                hello->start();
                sleep(3);
                std::cout<<"sleep 3"<<std::endl;
        }
 while(true)
 {
         sleep(1);
         std::cout<<"sleep 1s"<<std::endl;
 }
 return 0;
}

//各位大神,问题如下,急急急:
1.boost::thread或者boost::thread_group,在创建线程时会绑定一个函数对象(暂时记录为FuncA),那什么时候这个函数对象生命周期结束?是join或者detach函数调用之后吗?有没有从源码层大概分析,解释下释放这个FuncA函数对象资源相关参考信息?
2.是否join或者detach不能在本身类似于HelloWorl析构函数中调用,这是个禁忌吗?

c++
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
caffe安装过程中boost::未定义问题

各位大神,我在ubuntu16.04中安装caffe,进行到make all的时候报了如下错误: CXX/LD -o .build_release/test/test_all.testbin src/caffe/test/test_caffe_main.cpp .build_release/src/caffe/test/test_benchmark.o:在函数‘void boost::this_thread::sleep<boost::date_time::subsecond_duration<boost::posix_time::time_duration, 1000l> >(boost::date_time::subsecond_duration<boost::posix_time::time_duration, 1000l> const&)’中: test_benchmark.cpp:(.text._ZN5boost11this_thread5sleepINS_9date_time18subsecond_durationINS_10posix_time13time_durationELl1000EEEEEvRKT_[_ZN5boost11this_thread5sleepINS_9date_time18subsecond_durationINS_10posix_time13time_durationELl1000EEEEEvRKT_]+0x25a):对‘boost::this_thread::hidden::sleep_until(timespec const&)’未定义的引用 .build_release/lib/libcaffe.so:对‘boost::thread::start_thread_noexcept()’未定义的引用 .build_release/lib/libcaffe.so:对‘boost::thread::detach()’未定义的引用 .build_release/lib/libcaffe.so:对‘boost::detail::thread_data_base::~thread_data_base()’未定义的引用 .build_release/lib/libcaffe.so:对‘boost::thread::native_handle()’未定义的引用 .build_release/lib/libcaffe.so:对‘boost::thread::interrupt()’未定义的引用 .build_release/lib/libcaffe.so:对‘boost::this_thread::interruption_point()’未定义的引用 .build_release/lib/libcaffe.so:对‘boost::detail::set_tss_data(void const*, boost::shared_ptr<boost::detail::tss_cleanup_function>, void*, bool)’未定义的引用 .build_release/lib/libcaffe.so:对‘boost::thread::interruption_requested() const’未定义的引用 .build_release/lib/libcaffe.so:对‘vtable for boost::detail::thread_data_base’未定义的引用 .build_release/lib/libcaffe.so:对‘boost::detail::get_current_thread_data()’未定义的引用 .build_release/lib/libcaffe.so:对‘boost::thread::joinable() const’未定义的引用 .build_release/lib/libcaffe.so:对‘typeinfo for boost::detail::thread_data_base’未定义的引用 .build_release/lib/libcaffe.so:对‘boost::detail::get_tss_data(void const*)’未定义的引用 .build_release/lib/libcaffe.so:对‘boost::thread::join_noexcept()’未定义的引用 collect2: error: ld returned 1 exit status Makefile:603: recipe for target '.build_release/test/test_all.testbin' failed make: *** [.build_release/test/test_all.testbin] Error 1 一直没有找到有效的解决办法.麻烦遇到过的朋友指点迷津.定重谢!

c++多线程问题detach和join

c++并发编程实战上说,必须在线程结束前调用detach或者jion。如果线程结束再去分离,会出问题。 我的疑问是这么看来的话,c++根本就没有保证安全啊,即便detach在线程运行后一句就立马调用,也不能保证这是在线程结束前调用的啊,在这一块儿c++11是怎么处理的

C++ thread的detach函数问题??

``` #include<iostream> #include<thread> using namespace std; void function_1() { std::cout << "Hello,world!" << std::endl; } int main() { std::thread t1(function_1); //t1 starts running. //t1.join(); //main thread waits for t1 finish .等待子线程my_thread执行完之后,主线程才可以继续执行下,此时主线程会释放掉执行完后的子线程资源。 t1.detach(); system("pause"); return 0; } ```但是执行结果还是会把“Hello,world! ”输出,这是程序哪里出了问题??

qt std::thread线程如何发送一个信号调用主线程的一个函数

qt按钮下新建了一个线程 std::thread th1(&MainWindow::runTest,this,str_ModelName); th1.detach(); connect(th1,SIGNAL(robotStat(int)),this,SLOT(runTest1(int))); 想要用runtest里面的一个信号,去调用runtest1这个函数, 编译th1不能转为qobject*,请问如何连接

c++/clr dll工程中,定义一个全局对象,退出dll释放时,atlunadvise返回rpc_e_wrong_thread

环境:c++/clr,引用c# dll 1.一个类CManager,其中定义了一个引用过c# dll的类对象,该对象会调用c#的函数 2.定义一个全局对象CManager g_global,CManager类中创建一个连接点指针 3.CManager的构造函数中,创建了连接点指针atladvise返回值S_OK 4.该dll被一个exe引用,其中函数都正常,现让exe退出 5.在dllmain中,dll detach时,主动调用g_global析构,释放的时候atlunadvise返回rpc_e_wrong_thread, 求大神指点一下,谢谢!

Python 调用C++ dll库文件函数提示WindowsError: exception: access violation writing 0x00905A4D

.H文件如下: /* 视频解码 */ #ifndef __BLL_AUTELVIDEODECODE_H #define __BLL_AUTELVIDEODECODE_H #ifdef AUTELVIDEODECODE_EXPORTS #define AUTELVIDEODECODE_API __declspec(dllexport) #else #define AUTELVIDEODECODE_API __declspec(dllimport) #endif #include "bll/UDPClient/UDPAsyncClient.h" #include "bll/DataManager/DataManager.h" #include "bll/Utils/CommonFuntion.h" #include "bll/frame.h" #include "bll/video_data_mgn.h" #include "bll/h264.h" extern "C" { //编码 #include "libavcodec/avcodec.h" //封装格式处理 #include "libavformat/avformat.h" //像素处理 #include "libswscale/swscale.h" #include "libavutil/avutil.h" #include "libavutil/imgutils.h" }; #pragma comment(lib,"avutil.lib") #pragma comment(lib,"avformat.lib") #pragma comment(lib,"avcodec.lib") #pragma comment(lib,"swscale.lib") #define VIDEO_UDP_PORT (1234) #define min(a, b) ((a) < (b) ? (a) : (b)) #define MAX_RECVBUF_SIZE (64 * 1024) #define MAX_FRAME_SIZE (1024 * 1024) #pragma pack(push, 1) struct Decoder { AVCodec *codec; AVFrame *frame; AVCodecContext *dec_ctx; }; typedef struct { uint8_t *data; int size; int64_t pts; int keyframe; int decode_only; } VideoPacket; typedef struct { int width; int height; int64_t pts; int keyframe; int decode_only; int opaque; uint8_t *data; int size; } YuvFrame; #pragma pack(pop) typedef void (WINAPIV *yuvFrame_func)(YuvFrame *yuv); class AUTELVIDEODECODE_API CAutelVideoDecode { public: explicit CAutelVideoDecode(std::string strHost="", int nPort=VIDEO_UDP_PORT); ~CAutelVideoDecode(void); inline void SetYuvframeCallback(yuvFrame_func pfn) { m_pfnyuvFrame = pfn; } //functions private: //通过udp实时获取视频数据包线程 void StartRecvPacketThread(); void StopRecvPacketThread(); static int WINAPIV recv_video_data_func(char* buf, int length, void* ctx, void* pObj); void DoRecvPacket(); static DWORD ThRecvPacket(LPVOID lpParam); //从buf里面读取视频帧数据进行渲染线程 void StartRenderThread(); void StopRenderThread(); void DoRenderFrame(); static DWORD ThRenderFrame(LPVOID lpParam); Decoder *Decoder_Create(void); int Decoder_Destroy(); int Decoder_Decode(VideoPacket *inpkt, YuvFrame *frame); int get_video_frame(AVFrame *frame, YuvFrame *yuv); void PushFrame(YuvFrame frame); YuvFrame FrontFrame(); //params private: //通过udp实时获取视频数据包线程 HANDLE m_hRecvVideoPacket; bool m_bStopRecvVideoPacket; //从buf里面读取视频帧数据进行渲染线程 HANDLE m_hRenderFrame; bool m_bStopRender; CUDPAsyncClient *m_pUdpClient; std::string m_strHostAddr; int m_udpPort; Decoder *m_pDecoder; yuvFrame_func m_pfnyuvFrame; typedef std::queue<YuvFrame> QUEUE_YUVFRAME; QUEUE_YUVFRAME m_que_yuvframe; CRITICAL_SECTION m_cri_yuvFramequeLocker; }; #endif CPP文件 // dllmain.cpp : Defines the entry point for the DLL application. #include "stdafx.h" #include "AutelVideoDecode.h" BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: break; } return TRUE; } extern "C" { AUTELVIDEODECODE_API CAutelVideoDecode* AutelVideoDecode() { return new CAutelVideoDecode(); } AUTELVIDEODECODE_API void SetYuvframeCallback(CAutelVideoDecode* pAutel, yuvFrame_func pfn) { pAutel->SetYuvframeCallback(pfn); } } #####编译成AutelVideoDecode.dll库后供python2.7程序调用。 ####Python程序如下 import sys,pygame import YUVFrame import thread from ctypes import * ObjAutelvideodecodeDLL = windll.LoadLibrary(".\\bin\\autelvideodecode.dll") class AutoTestAutelRealTimeVideo: def __init__(self): pygame.init() self.size = width, height = 1280, 720 self.black = 0, 0, 0 self.YUVFrame = None self.overlay =None self.IYUV = pygame.IYUV_OVERLAY self.lock = thread.allocate_lock() CALLFUCTION = CFUNCTYPE(None, POINTER(YUVFrame.YUVFrame)) self.PrenderYuvframe = CALLFUCTION(self.renderYuvframe) #ObjAutelvideodecodeDLL.AutelVideoDecode.argtype=c_char_p ObjAutelvideodecodeDLL.AutelVideoDecode.restype = c_void_p ObjAutelvideodecodeDLL.SetYuvframeCallback.argtypes = (c_void_p,c_void_p) #ObjAutelvideodecodeDLL.SetYuvframeCallback.restype = None self.AutelObj = ObjAutelvideodecodeDLL.AutelVideoDecode() def ...... 编译后出错: Connected to pydev debugger (build 129.782) Traceback (most recent call last): File "C:\Program Files (x86)\JetBrains\PyCharm 2.7.3\helpers\pydev\pydevd.py", line 1481, in <module> debugger.run(setup['file'], None, None) File "C:\Program Files (x86)\JetBrains\PyCharm 2.7.3\helpers\pydev\pydevd.py", line 1124, in run pydev_imports.execfile(file, globals, locals) #execute the script File "E:/AutoTestAutelRealTimeVideo/AutoTestAutelRealTimeVideo.py", line 84, in <module> test() File "E:/AutoTestAutelRealTimeVideo/AutoTestAutelRealTimeVideo.py", line 66, in test test = AutoTestAutelRealTimeVideo() File "E:/AutoTestAutelRealTimeVideo/AutoTestAutelRealTimeVideo.py", line 25, in __init__ self.AutelObj = ObjAutelvideodecodeDLL.AutelVideoDecode() WindowsError: exception: access violation writing 0x00905A4D

C#程序关闭,进程还在运行

写了一个C#的程序,调用了一个C++的dll,在C++的DLLMain中下面这样写的,特意在DLL_PROCESS_DETACH中关闭了线程,但那个MessageBox在关闭C#程序时并没有弹出来,是不是意味着我所有在dll中开的线程都没关闭?为什么会这样呢? ``` BOOL APIENTRY DllMain( HMODULE hModule, // handle to DLL module DWORD ul_reason_for_call, // reason for calling function LPVOID lpReserved // reserved ) { // Perform actions based on the reason for calling. switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: // Initialize once for each new process.Return FALSE to fail DLL load. { SetDllNCCallback(rtm_InterpStartEnd); SendNCDriverUserDecodeEvent(); pctr_dataShm = (LPCTRDATA)malloc(sizeof(Shmctr_data));//初始化全局控制变量 if(pctr_dataShm == NULL) { MessageBox(NULL,TEXT("can not alloc heapmemory in pctr_dataShm"),TEXT("Interpolation Error"),NULL); return 1; } hrtm_PositCtrl_Trd = CreateThread(NULL, 0, rtm_PositCtrl_Trd, NULL,CREATE_SUSPENDED, NULL); SetThreadPriority(hrtm_PositCtrl_Trd, THREAD_PRIORITY_TIME_CRITICAL); ResumeThread(hrtm_PositCtrl_Trd); hrtm_VelCtrl_Trd = CreateThread(NULL, 0, rtm_VelCtrl_Trd, NULL,CREATE_SUSPENDED, NULL); SetThreadPriority(hrtm_VelCtrl_Trd, THREAD_PRIORITY_HIGHEST); ResumeThread(hrtm_VelCtrl_Trd); hrtm_DecodFifo_Trd = CreateThread(NULL, 0, rtm_DecodFifo_Trd, NULL,CREATE_SUSPENDED, NULL); SetThreadPriority(hrtm_DecodFifo_Trd, THREAD_PRIORITY_ABOVE_NORMAL); ResumeThread(hrtm_DecodFifo_Trd); hrtm_Intrp_Trd = CreateThread(NULL, 0, rtm_Intrp_Trd, NULL,CREATE_SUSPENDED, NULL); SetThreadPriority(hrtm_Intrp_Trd, THREAD_PRIORITY_NORMAL); ResumeThread(hrtm_Intrp_Trd); hrtm_Prd_2ms = CreateThread(NULL,0,rtm_Prd_2ms,0,0,NULL); break; } case DLL_THREAD_ATTACH: //MessageBox(NULL,TEXT("Enter DLL_THREAD_ATTACH"),TEXT("Interpolation Inform"),NULL); break; case DLL_THREAD_DETACH: //MessageBox(NULL,TEXT("Enter DLL_THREAD_DETACH"),TEXT("Interpolation Inform"),NULL); break; case DLL_PROCESS_DETACH: CloseHandle(hrtm_PositCtrl_Trd); free(pctr_dataShm); //释放全局控制量 pctr_dataShm = NULL; CloseHandle(hrtm_PositCtrl_Trd); CloseHandle(hrtm_VelCtrl_Trd); CloseHandle(hrtm_DecodFifo_Trd); CloseHandle(hrtm_Intrp_Trd); CloseHandle(hrtm_Prd_2ms); MessageBox(NULL,TEXT("Leave Interpolation dll"),TEXT("Interpolation Inform"),NULL); break; } return TRUE; } ```

C++ 线程和仿函数的问题??

``` #include<iostream> #include<thread> using namespace std; void function_1() { std::cout << "Hello,world!" << std::endl; } class Fctor { //仿函数 public: void operator()() { //对()进行重载 for (int i = 0; i > -100; i--) { cout << "from t1 " << i << endl; } } }; int main() { //Fctor fct; std::thread t1((Fctor())); //t1 starts running. 实例化一个线程对象t1 try { for (int i = 0; i < 100; i++) cout << "from main: " << i << endl; } catch (...) { t1.join(); throw; } t1.join(); //t1.detach(); return 0; } ``` 其中这句 std::thread t1((Fctor())); 为什么要再“Fctor()”两边还要加括号?否则“ t1.join();”这句会提示错误?? 还有能解释下执行结果吗? ![图片说明](https://img-ask.csdn.net/upload/201601/08/1452229227_778741.jpg)

pthread_create后子线程输出了两次

#include <stdio.h> #include <errno.h> #include <string.h> #include <unistd.h> #include <pthread.h> void *start_handler(void *); int main(void) { pthread_t tid; int err; if(err = pthread_create(&tid, NULL, start_handler, NULL)) { fprintf(stderr, "Create thread: %s\n", strerror(err)); return -1; } printf("OK\n"); return 0; } void *start_handler(void *arg) { int err; if(err = pthread_detach(pthread_self())) { fprintf(stderr, "Detach thread: %s\n", strerror(err)); pthread_exit((void *)-1); } printf("Start!\n"); pthread_exit((void *)1); }

您可以在Golang中使用SQLite ATTACH和DETACH吗

<div class="post-text" itemprop="text"> <p>I am using <a href="https://github.com/mattn/go-sqlite3" rel="nofollow">https://github.com/mattn/go-sqlite3</a> in a Golang application. I need to use multiple databases, and was wondering whether I can use ATTACH and DETACH in Golang (<a href="http://sqlite.org/lang_attach.html" rel="nofollow">http://sqlite.org/lang_attach.html</a>).</p> <p>I don't have any code right now, because I don't know how else to tackle this problem except creating two database connections and joining data in the application:</p> <pre><code>db1, err := sql.Open("sqlite3", "./db1.db") db2, err := sql.Open("sqlite3", "./db2.db") // query db1 and db2 // put into map // join data </code></pre> <p>It would be much easier if you could use:</p> <pre><code>attach database database1.db as db1; attach database database2.db as db2; select * from db1.SomeTable a inner join db2.SomeTable b on b.SomeColumn = a.SomeColumn; </code></pre> </div>

laravel sync和detach不能用于删除所有实例

<div class="post-text" itemprop="text"> <p>I'm working on a project where users can work on multiple projects and projects can have multiple users working on it. With this project I am using the sync method to add and delete instances in the pivot table. Whenever I am using sync with an empty array or detach to delete all instances that have a certain project id, it doesn't work and the instances keep existing.</p> <p>While the sync with parameters work to add data to the database I find it very strange that deleting wont work. Same with a sync on only one instance while there are more instances in the database, it will delete the other instances and keep the one.</p> <p>My function:</p> <pre><code>public function update(CreateProjectRequest $request) { if($request-&gt;get('contribute')) { foreach($request-&gt;get('contribute') as $k =&gt; $contribute) { if($contribute == 1) { $this-&gt;project = $this-&gt;project-&gt;find($request-&gt;project_id); $keys[] = $k; } } } if(isset($keys)) { $this-&gt;project-&gt;users()-&gt;sync($keys); } else { </code></pre> <blockquote> <p>$this-&gt;project-&gt;users()-&gt;detach();</p> </blockquote> <pre><code> } $this-&gt;project = $this-&gt;project-&gt;find($request-&gt;project_id); $this-&gt;project-&gt;fill($request-&gt;input())-&gt;save(); return redirect('project'); } </code></pre> </div>

jquery中detach()和remove()在append方法中的定义

<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script> $(document).ready(function(){ $("#btn1").click(function(){ $("body").append($("#p1").detach()); }); $("#btn2").click(function(){ $("body").append($("#p2").remove()); }); $("p").click(function(){ $(this).animate({fontSize: "+=1px"}) }); }); </script> </head> <body> 9 <p id="p1"><b>This paragraph will keep its click event even after it is moved.</b></p> <p id="p2">This paragraph will not keep its click event after it is moved.</p> <button id="btn1">Detach and append p element</button> <button id="btn2">Remove and append p element</button> </body> </html> 来自jquery教程的代码入上面所示,我知道detach()意思是删除并缓存 而remove()的意思是删除 可是使用append($("#p1").detach())和append($("#p2").remove())是什么意思啊?

C++ 怎样回收线程,。。。

我想实现一个线程池。想到这样一个问题,一个线程被创建以后自动运行,运行结束后自动释放。 比如下面代码中的t运行结束后就释放掉了。那么怎样实现对一个线程的二次使用呢,就比如下面的t运行一次后不要自动释放,重新回收后可以为我执行别的任务。 void fun() { cout<<"thread"<<endl ; } void main() { thread t(fun) ; t.detach() ; //t.join(); return ; }

C# 使用 Widgets must be created in the GUI thread

在使用C#调用qt的dll时,第一次调用的一般没事,第二,三次就会出现Widgets must be created in the GUI thread。 这是我用的qt中的代码 BOOL WINAPI DllMain( HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpvReserved*/ ) { static bool ownApplication = FALSE; if ( dwReason == DLL_PROCESS_ATTACH ) { ownApplication = QMfcApp::pluginInstance( hInstance ); } if ( dwReason == DLL_PROCESS_DETACH && ownApplication ) { delete qApp; } return TRUE; } 这是C#中调用qt的代码 myfun1 = new DLDApi(); myfun1.LoadDll(@"D:\MvcAAA\MvcAAA\bin\meshlab.dll"); // 加载 "Count.dll" myfun1.LoadFun("Test"); // 调入函数 count, "_count@4" 是它的入口,可通过 Depends 查看 object[] Parameters = new object[] { (int)5}; // 实参为 0 Type[] ParameterTypes = new Type[] { typeof(int) }; // 实参类型为 int DLDApi.ModePass[] themode = new DLDApi.ModePass[] { DLDApi.ModePass.ByValue }; // 传送方式为值传 Type Type_Return = typeof(int); // 返回类型为 int // 弹出提示框,显示调用 myfun.Invoke 方法的结果,即调用 count 函数 int i = (int)myfun1.Invoke(Parameters, ParameterTypes, themode, Type_Return); myfun1.UnLoadDll(); C#代码在运行**UnLoadDll**卸载dll方法后,DLL_PROCESS_DETACH中断delete app并没有被执行,整个dll里面有一个qt的线程,卸载了dll后线程并没有被关闭,导致第二次运行的时候无法再次创建QWidegt对象。 想要请教以下各位,如何让在调用完dll后让中的线程关闭掉。是应该写在C++的这个dll中还是写在C#的调用中, 同时这个qt的dll中有一个对象My3Doperation,这个对象继承与QWidget,如何在使用完这个对象后将创建的线程彻底删除。 extern "C" __declspec(dllexport) int Test(int fileName) { My3Doperation model; //计算代码 return fileName+5; }

找不到Ajax Json路径

<div class="post-text" itemprop="text"> <p>I am not bad in C++ but I have a terrible knowledge about web so please consider that the answer to this question will be simple.</p> <p>I have found a C++ library for a webserver <a href="https://github.com/eidheim/Simple-Web-Server" rel="nofollow">here on github</a>.</p> <p>It works fine when I enter <a href="http://localhost:8080/" rel="nofollow">http://localhost:8080/</a> in my browser to test its HTML page. I also have tested:</p> <pre><code>http://localhost:8080/info http://localhost:8080/match/8796 </code></pre> <p>They work fine too.</p> <p>However, when I try to test its Ajax/Json, it does not work for me using the following code in my firefox browser console.</p> <pre><code>$.post( "json", {firstName: "John",lastName: "Smith",age: 25} ); not well-formed json:1:18 ---&gt; Could not open path /json </code></pre> <p>I tried </p> <pre><code>$.post( "string", {firstName: "John",lastName: "Smith",age: 25} ); </code></pre> <p>and received similar result.</p> <p>Where am I doing mistake?</p> <hr> <p>The C++ code in short, hosts a server on port 8080, responds to</p> <pre><code>server.resource["^/string$"]["POST"] server.resource["^/json$"]["POST"] server.resource["^/info$"]["GET"] server.resource["^/work$"]["GET"] server.default_resource["GET"] </code></pre> <p>The client examples are:</p> <pre><code> //Client examples HttpClient client("localhost:8080"); auto r1=client.request("GET", "/match/123"); cout &lt;&lt; r1-&gt;content.rdbuf() &lt;&lt; endl; string json_string="{\"firstName\": \"John\",\"lastName\": \"Smith\",\"age\": 25}"; auto r2=client.request("POST", "/string", json_string); cout &lt;&lt; r2-&gt;content.rdbuf() &lt;&lt; endl; auto r3=client.request("POST", "/json", json_string); cout &lt;&lt; r3-&gt;content.rdbuf() &lt;&lt; endl; </code></pre> <hr> <p>http_examples.cpp <a href="https://github.com/eidheim/Simple-Web-Server/blob/master/http_examples.cpp" rel="nofollow">[link]</a></p> <pre><code>#include "server_http.hpp" #include "client_http.hpp" //Added for the json-example #define BOOST_SPIRIT_THREADSAFE #include &lt;boost/property_tree/ptree.hpp&gt; #include &lt;boost/property_tree/json_parser.hpp&gt; //Added for the default_resource example #include &lt;fstream&gt; #include &lt;boost/filesystem.hpp&gt; #include &lt;vector&gt; #include &lt;algorithm&gt; using namespace std; //Added for the json-example: using namespace boost::property_tree; typedef SimpleWeb::Server&lt;SimpleWeb::HTTP&gt; HttpServer; typedef SimpleWeb::Client&lt;SimpleWeb::HTTP&gt; HttpClient; //Added for the default_resource example void default_resource_send(const HttpServer &amp;server, shared_ptr&lt;HttpServer::Response&gt; response, shared_ptr&lt;ifstream&gt; ifs, shared_ptr&lt;vector&lt;char&gt; &gt; buffer); int main() { //HTTP-server at port 8080 using 1 thread //Unless you do more heavy non-threaded processing in the resources, //1 thread is usually faster than several threads HttpServer server(8080, 1); //Add resources using path-regex and method-string, and an anonymous function //POST-example for the path /string, responds the posted string server.resource["^/string$"]["POST"]=[](shared_ptr&lt;HttpServer::Response&gt; response, shared_ptr&lt;HttpServer::Request&gt; request) { //Retrieve string: auto content=request-&gt;content.string(); //request-&gt;content.string() is a convenience function for: //stringstream ss; //ss &lt;&lt; request-&gt;content.rdbuf(); //string content=ss.str(); *response &lt;&lt; "HTTP/1.1 200 OK Content-Length: " &lt;&lt; content.length() &lt;&lt; " " &lt;&lt; content; }; //POST-example for the path /json, responds firstName+" "+lastName from the posted json //Responds with an appropriate error message if the posted json is not valid, or if firstName or lastName is missing //Example posted json: //{ // "firstName": "John", // "lastName": "Smith", // "age": 25 //} server.resource["^/json$"]["POST"]=[](shared_ptr&lt;HttpServer::Response&gt; response, shared_ptr&lt;HttpServer::Request&gt; request) { try { ptree pt; read_json(request-&gt;content, pt); string name=pt.get&lt;string&gt;("firstName")+" "+pt.get&lt;string&gt;("lastName"); *response &lt;&lt; "HTTP/1.1 200 OK Content-Length: " &lt;&lt; name.length() &lt;&lt; " " &lt;&lt; name; } catch(exception&amp; e) { *response &lt;&lt; "HTTP/1.1 400 Bad Request Content-Length: " &lt;&lt; strlen(e.what()) &lt;&lt; " " &lt;&lt; e.what(); } }; //GET-example for the path /info //Responds with request-information server.resource["^/info$"]["GET"]=[](shared_ptr&lt;HttpServer::Response&gt; response, shared_ptr&lt;HttpServer::Request&gt; request) { stringstream content_stream; content_stream &lt;&lt; "&lt;h1&gt;Request from " &lt;&lt; request-&gt;remote_endpoint_address &lt;&lt; " (" &lt;&lt; request-&gt;remote_endpoint_port &lt;&lt; ")&lt;/h1&gt;"; content_stream &lt;&lt; request-&gt;method &lt;&lt; " " &lt;&lt; request-&gt;path &lt;&lt; " HTTP/" &lt;&lt; request-&gt;http_version &lt;&lt; "&lt;br&gt;"; for(auto&amp; header: request-&gt;header) { content_stream &lt;&lt; header.first &lt;&lt; ": " &lt;&lt; header.second &lt;&lt; "&lt;br&gt;"; } //find length of content_stream (length received using content_stream.tellp()) content_stream.seekp(0, ios::end); *response &lt;&lt; "HTTP/1.1 200 OK Content-Length: " &lt;&lt; content_stream.tellp() &lt;&lt; " " &lt;&lt; content_stream.rdbuf(); }; //GET-example for the path /match/[number], responds with the matched string in path (number) //For instance a request GET /match/123 will receive: 123 server.resource["^/match/([0-9]+)$"]["GET"]=[&amp;server](shared_ptr&lt;HttpServer::Response&gt; response, shared_ptr&lt;HttpServer::Request&gt; request) { string number=request-&gt;path_match[1]; *response &lt;&lt; "HTTP/1.1 200 OK Content-Length: " &lt;&lt; number.length() &lt;&lt; " " &lt;&lt; number; }; //Get example simulating heavy work in a separate thread server.resource["^/work$"]["GET"]=[&amp;server](shared_ptr&lt;HttpServer::Response&gt; response, shared_ptr&lt;HttpServer::Request&gt; /*request*/) { thread work_thread([response] { this_thread::sleep_for(chrono::seconds(5)); string message="Work done"; *response &lt;&lt; "HTTP/1.1 200 OK Content-Length: " &lt;&lt; message.length() &lt;&lt; " " &lt;&lt; message; }); work_thread.detach(); }; //Default GET-example. If no other matches, this anonymous function will be called. //Will respond with content in the web/-directory, and its subdirectories. //Default file: index.html //Can for instance be used to retrieve an HTML 5 client that uses REST-resources on this server server.default_resource["GET"]=[&amp;server](shared_ptr&lt;HttpServer::Response&gt; response, shared_ptr&lt;HttpServer::Request&gt; request) { const auto web_root_path=boost::filesystem::canonical("web"); boost::filesystem::path path=web_root_path; path/=request-&gt;path; if(boost::filesystem::exists(path)) { path=boost::filesystem::canonical(path); //Check if path is within web_root_path if(distance(web_root_path.begin(), web_root_path.end())&lt;=distance(path.begin(), path.end()) &amp;&amp; equal(web_root_path.begin(), web_root_path.end(), path.begin())) { if(boost::filesystem::is_directory(path)) path/="index.html"; if(boost::filesystem::exists(path) &amp;&amp; boost::filesystem::is_regular_file(path)) { auto ifs=make_shared&lt;ifstream&gt;(); ifs-&gt;open(path.string(), ifstream::in | ios::binary); if(*ifs) { //read and send 128 KB at a time streamsize buffer_size=131072; auto buffer=make_shared&lt;vector&lt;char&gt; &gt;(buffer_size); ifs-&gt;seekg(0, ios::end); auto length=ifs-&gt;tellg(); ifs-&gt;seekg(0, ios::beg); *response &lt;&lt; "HTTP/1.1 200 OK Content-Length: " &lt;&lt; length &lt;&lt; " "; default_resource_send(server, response, ifs, buffer); return; } } } } string content="Could not open path "+request-&gt;path; *response &lt;&lt; "HTTP/1.1 400 Bad Request Content-Length: " &lt;&lt; content.length() &lt;&lt; " " &lt;&lt; content; }; thread server_thread([&amp;server](){ //Start server server.start(); }); //Wait for server to start so that the client can connect this_thread::sleep_for(chrono::seconds(1)); //Client examples HttpClient client("localhost:8080"); auto r1=client.request("GET", "/match/123"); cout &lt;&lt; r1-&gt;content.rdbuf() &lt;&lt; endl; string json_string="{\"firstName\": \"John\",\"lastName\": \"Smith\",\"age\": 25}"; auto r2=client.request("POST", "/string", json_string); cout &lt;&lt; r2-&gt;content.rdbuf() &lt;&lt; endl; auto r3=client.request("POST", "/json", json_string); cout &lt;&lt; r3-&gt;content.rdbuf() &lt;&lt; endl; server_thread.join(); return 0; } void default_resource_send(const HttpServer &amp;server, shared_ptr&lt;HttpServer::Response&gt; response, shared_ptr&lt;ifstream&gt; ifs, shared_ptr&lt;vector&lt;char&gt; &gt; buffer) { streamsize read_length; if((read_length=ifs-&gt;read(&amp;(*buffer)[0], buffer-&gt;size()).gcount())&gt;0) { response-&gt;write(&amp;(*buffer)[0], read_length); if(read_length==static_cast&lt;streamsize&gt;(buffer-&gt;size())) { server.send(response, [&amp;server, response, ifs, buffer](const boost::system::error_code &amp;ec) { if(!ec) default_resource_send(server, response, ifs, buffer); else cerr &lt;&lt; "Connection interrupted" &lt;&lt; endl; }); } } } </code></pre> </div>

如何卸载一个包不重新启动 r?

<div class="post-text" itemprop="text"> <p>I'd like to unload a package without having to restart R (mostly because restarting R as I try out different, conflicting packages is getting frustrating, but conceivably this could be used in a program to use one function and then another--although namespace referencing is probably a better idea for that use).</p> <p><code>?library</code> doesn't show any options that would unload a package.</p> <p>There is a <a href="https://stackoverflow.com/questions/3536036/rmlist-ls-doesnt-completely-clear-the-workspace/3537342#3537342">suggestion</a> that <code>detach</code> can unload package, but the following both fail:</p> <pre><code>detach(vegan) </code></pre> <blockquote> <p>Error in <code>detach(vegan)</code> : invalid <code>name</code> argument</p> </blockquote> <pre><code>detach("vegan") </code></pre> <blockquote> <p>Error in <code>detach("vegan")</code> : invalid <code>name</code> argument</p> </blockquote> <p>So how do I unload a package?</p> </div> <p>转载于:https://stackoverflow.com/questions/6979917/how-to-unload-a-package-without-restarting-r</p>

Laravel - 在attach()和detach()之后检查查询执行

<div class="post-text" itemprop="text"> <p>After I execute this</p> <pre><code>$shop-&gt;articles()-&gt;attach($article_id); </code></pre> <p>or this</p> <pre><code>$shop-&gt;articles()-&gt;detach($article_id); </code></pre> <p>how do I make sure they actually get executed? In the first case it returns void, but also it saves automatically so I cannot use the save function to check it. In the second case it returns int, but what does it represent?</p> </div>

MFC CBitmap 和 HBITMAP 析构问题

我在一个dialog里面用CImageList加载多个.bmp格式位图。 1 我定义了一个HBITMAP hBitmapHouse 变量,CBitmap pBitmapHouse[9]数组; 在for循环里面LoadImage不同的图片 代码如下: for(i = 0; i < 9; i++) { tempFileName = "res/dockhouse" + to_string(i) + ".bmp"; hBitmapHouse = (HBITMAP)LoadImage(AfxGetInstanceHandle(),tempFileName.c_str(), IMAGE_BITMAP,0,0,LR_LOADFROMFILE); pBitmapHouse[i].Attach(hBitmapHouse); m_ImgHouse.Add(&pBitmapHouse[i],RGB(0,0,0)); } m_ImgHouse 是dialog的一个成员。 问题一: 这个hBitmapHouse变量循环一次,指向新的内存。pBitmapHouse执行析构的时候,会把相应的图片的内存会释放掉吗? 问题二:我是在initdialog这个函数里面定义的pBitmapHouse这个变量,它在这个函数结束的时候要执行析构函数,我没有detach, pBitmapHouse应该会把自己的对象和它对应的图片的内存都释放掉, 为什么我的dialog还是正常显示图片? 问题三:我是不是应该在这个dialog类里面定义CBitmap数组,在这个initdialog里面用一个hBitmapHouse,来加载不同的图片,等到这个对话框析构的时候,会自动调用CBitmap,这样,图片和CBitmap对象都释放掉了?

YOLOv3目标检测实战:训练自己的数据集

YOLOv3目标检测实战:训练自己的数据集

150讲轻松搞定Python网络爬虫

150讲轻松搞定Python网络爬虫

实用主义学Python(小白也容易上手的Python实用案例)

实用主义学Python(小白也容易上手的Python实用案例)

我说我不会算法,阿里把我挂了。

不说了,字节跳动也反手把我挂了。

立方体线框模型透视投影 (计算机图形学实验)

计算机图形学实验 立方体线框模型透视投影 的可执行文件,亲测可运行,若需报告可以联系我,期待和各位交流

2019 AI开发者大会

2019 AI开发者大会

组成原理课程设计(实现机器数的真值还原等功能)

实现机器数的真值还原(定点小数)、定点小数的单符号位补码加减运算、定点小数的补码乘法运算和浮点数的加减运算。

C/C++跨平台研发从基础到高阶实战系列套餐

一 专题从基础的C语言核心到c++ 和stl完成基础强化; 二 再到数据结构,设计模式完成专业计算机技能强化; 三 通过跨平台网络编程,linux编程,qt界面编程,mfc编程,windows编程,c++与lua联合编程来完成应用强化 四 最后通过基于ffmpeg的音视频播放器,直播推流,屏幕录像,

MFC一站式终极全套课程包

该套餐共包含从C小白到C++到MFC的全部课程,整套学下来绝对成为一名C++大牛!!!

软件测试2小时入门

软件测试2小时入门

三个项目玩转深度学习(附1G源码)

三个项目玩转深度学习(附1G源码)

计算机图形学-球的光照模型课程设计

计算机图形学-球的光照模型,有代码完美运行,有课程设计书

Linux常用命令大全(非常全!!!)

Linux常用命令大全(非常全!!!) 最近都在和Linux打交道,感觉还不错。我觉得Linux相比windows比较麻烦的就是很多东西都要用命令来控制,当然,这也是很多人喜欢linux的原因,比较短小但却功能强大。我将我了解到的命令列举一下,仅供大家参考: 系统信息 arch 显示机器的处理器架构 uname -m 显示机器的处理器架构 uname -r 显示正在使用的内核版本 d...

因为看了这些书,我大二就拿了华为Offer

四年了,四年,你知道大学这四年我怎么过的么?

深度学习原理+项目实战+算法详解+主流框架(套餐)

深度学习系列课程从深度学习基础知识点开始讲解一步步进入神经网络的世界再到卷积和递归神经网络,详解各大经典网络架构。实战部分选择当下最火爆深度学习框架PyTorch与Tensorflow/Keras,全程实战演示框架核心使用与建模方法。项目实战部分选择计算机视觉与自然语言处理领域经典项目,从零开始详解算法原理,debug模式逐行代码解读。适合准备就业和转行的同学们加入学习! 建议按照下列课程顺序来进行学习 (1)掌握深度学习必备经典网络架构 (2)深度框架实战方法 (3)计算机视觉与自然语言处理项目实战。(按照课程排列顺序即可)

fakeLocation13.5.1.zip

fakeLocation13.5.1 虚拟定位 ios13.5.1的最新驱动下载,iPhone/iPad免越狱虚拟定位工具Location-cleaned驱动已更新

UnityLicence

UnityLicence

Python可以这样学(第一季:Python内功修炼)

Python可以这样学(第一季:Python内功修炼)

Python+OpenCV计算机视觉

Python+OpenCV计算机视觉

土豆浏览器

土豆浏览器可以用来看各种搞笑、电影、电视剧视频

【数据结构与算法综合实验】欢乐连连看(C++ & MFC)案例

这是武汉理工大学计算机学院数据结构与算法综合实验课程的第三次项目:欢乐连连看(C++ & MFC)迭代开发代码。运行环境:VS2017。已经实现功能:开始游戏、消子、判断胜负、提示、重排、计时、帮助。

php+mysql学生成绩管理系统

学生成绩管理系统,分三个模块:学生,教师和管理员。 管理员模块:负责学生、老师信息的增删改;发布课程信息的增删改,以便让学生选课;审核老师提交的学生成绩并且打印成绩存档;按照课号查询每个课号的学生成绩

多功能数字钟.zip

利用数字电子计数知识设计并制作的数字电子钟(含multisim仿真),该数字钟具有显示星期、24小时制时间、闹铃、整点报时、时间校准功能

推荐24个国外黄色网站欣赏

在中国清朝,明黄色的衣服只有皇子才有资格穿,慢慢的黄色在中国就成了高贵的颜色。在人们的色彩印象中,黄色也表现为暂停。所以当你的网页设计采用黄色的时候,会让人们在你的网页前停留。 黄色,就像橙色和红色,黄色也是一个暖色。它有大自然、阳光、春天的涵义,而且通常被认为是一个快乐和有希望的色彩。黄色是所有色相中最能发光的颜色,给人轻快,透明,辉煌,充满希望的色彩印象。 黄色是一个高可见的色...

u-boot-2015.07.tar.bz2

uboot-2015-07最新代码,喜欢的朋友请拿去

一学即懂的计算机视觉(第一季)

一学即懂的计算机视觉(第一季)

学生成绩管理系统(PHP + MYSQL)

做的是数据库课程设计,使用的php + MySQL,本来是黄金搭配也就没啥说的,推荐使用wamp服务器,里面有详细的使用说明,带有界面的啊!呵呵 不行的话,可以给我留言!

Windows版YOLOv4目标检测实战:训练自己的数据集

Windows版YOLOv4目标检测实战:训练自己的数据集

C++语言基础视频教程

C++语言基础视频教程

玩转Python-Python3基础入门

玩转Python-Python3基础入门

2019校招硬件乐鑫+比特大陆笔试题

楼主水硕一枚,参加了2019年的秋招。自己总结了下乐鑫的笔试题目(现场笔试)以及网上考试的比特大陆的题目

相关热词 c# 按行txt c#怎么扫条形码 c#打包html c# 实现刷新数据 c# 两个自定义控件重叠 c#浮点类型计算 c#.net 中文乱码 c# 时间排序 c# 必备书籍 c#异步网络通信
立即提问