Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Multithreading 使用MFC清除ONC RPC SVC_RUN()的退出_Multithreading_Rpc_Sunrpc - Fatal编程技术网

Multithreading 使用MFC清除ONC RPC SVC_RUN()的退出

Multithreading 使用MFC清除ONC RPC SVC_RUN()的退出,multithreading,rpc,sunrpc,Multithreading,Rpc,Sunrpc,我对多线程代码还很陌生,所以我希望有人能帮我解决这个问题 我有一个由ONC/RPC服务器和其他东西组成的多部分程序(这些“东西”与我的问题无关,但它必须在服务器程序中)。因为svc_run()永远不会返回,我想我会把它放在它自己的线程中,在程序结束时,我会简单地终止线程,继续生活 然而,我的程序现在已经扩展,我希望干净、安全地退出或关闭ONC/RPC服务器,而不是终止线程。但是,我不知道如何安全地从svc_run()返回。有人能帮忙吗 我发现其他一些人也有同样的问题,但似乎没有人对此做出回应。我

我对多线程代码还很陌生,所以我希望有人能帮我解决这个问题

我有一个由ONC/RPC服务器和其他东西组成的多部分程序(这些“东西”与我的问题无关,但它必须在服务器程序中)。因为svc_run()永远不会返回,我想我会把它放在它自己的线程中,在程序结束时,我会简单地终止线程,继续生活

然而,我的程序现在已经扩展,我希望干净、安全地退出或关闭ONC/RPC服务器,而不是终止线程。但是,我不知道如何安全地从svc_run()返回。有人能帮忙吗

我发现其他一些人也有同样的问题,但似乎没有人对此做出回应。我尝试过简单地将svc_run()移动到与我的server_process()函数相同的文件中,但是fd_set的结构没有正确填充(所有内容都是0),函数失败

svc_run()在使用以下代码创建的dll中定义:

我正在提供代码的相关元素。还要注意,svc_exit()似乎不是我当前使用的onc/rpc系统的一部分

抱歉问了这么长的问题, 谢谢,

莱克斯

这是我的密码:

 //Code in Initialization of MFC Dialog
myThread = AfxBeginThread(startServing,NULL,THREAD_PRIORITY_NORMAL,0,0,NULL);

 // Thread that starts the server

 UINT __cdecl startServing(LPVOID pParam)
{
   if(server_process())
    AfxMessageBox(_T("Error Starting the VXI 11 Server."));

   AfxEndThread(0,TRUE); //I never get here.
   return 0;
 }

//How I would like to stop the thread:
void myDlg::OnBnClickedQuit()
{
   DWORD threadStatus;
   endThread = 1; //static or extern that could be monitored if svc_run() 
                  //wasn't in a dll
   threadStatus = WaitForSingleObject(myThread->m_hThread, INFINITE);
   OnOk(); //for the ok modal to close the progam

} 

//How I end up stopping my thread
void myDlg::OnBnClickedQuit()
{
   TerminateThread(myThread->m_hThread,1);
   OnOk(); //for the ok modal to close the progam

} 


int server_process()
{
  //Portmap and server registration code
  .
  .
  .
  .
   svc_run(); //ideally I'd be able to monitor a global in here
   (void)fprintf(stderr, "svc_run returned\n");
#ifdef WIN32
   rpc_nt_exit();
#endif
   return(1);

 }// end of server Process

// Function in the dll I'm calling
void svc_run()
{
#ifdef FD_SETSIZE
        fd_set readfds;
#else
      int readfds;
#endif /* def FD_SETSIZE */
#ifndef WIN32
    extern int errno;
#endif

    for (;;) { 
#ifdef FD_SETSIZE
    readfds = svc_fdset;
#else
    readfds = svc_fds;
#endif /* def FD_SETSIZE */
#ifdef WIN32
    switch (select(0 /* unused in winsock */, &readfds, NULL, NULL,
#else
    switch (select(_rpc_dtablesize(), &readfds, (int *)0, (int *)0,
#endif
               (struct timeval *)0)) {
    case -1:
#ifdef WIN32
        if (WSAerrno == EINTR) {
#else
        if (errno == EINTR) {
#endif
            continue;
        }
        perror("svc_run: - select failed");
        return;
    case 0:
        continue;
    default:
        svc_getreqset(&readfds);
       }
   }
}

答案就在你的问题里。您必须编写自己的
svc\u run()
,并使用以下条件更改无限循环:

while(!done) {
  select(....)
  svc_getreqset(&readfds);
}