当前位置: 首页>>代码示例>>C++>>正文


C++ ACE_Thread_Manager::spawn方法代码示例

本文整理汇总了C++中ACE_Thread_Manager::spawn方法的典型用法代码示例。如果您正苦于以下问题:C++ ACE_Thread_Manager::spawn方法的具体用法?C++ ACE_Thread_Manager::spawn怎么用?C++ ACE_Thread_Manager::spawn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ACE_Thread_Manager的用法示例。


在下文中一共展示了ACE_Thread_Manager::spawn方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: if

/*
fence: 1) send the heartbeat message to repo at regular basis. 1/1 minute, get back the messages,
calculate the digest, and send to localhost:9907
2)listens on localhost:9901, for the incoming raw inputs, calculate the digest, and send it to hub:10007
*/
int
ACE_TMAIN(int argc, ACE_TCHAR* argv[]){
  ACE_SOCK_Acceptor _9901acceptor;  

  ACE_INET_Addr _9901addr(9901);
  //create the acceptor
  if(_9901acceptor.open(_9901addr,1)==-1){
    ACE_ERROR_RETURN((LM_ERROR,
		      "%p\n","open"),1);
  }else if(_9901acceptor.get_local_addr(_9901addr)== -1){
    ACE_ERROR_RETURN((LM_ERROR,
		      "%p\n","get_local_addr"),1);
  }
  ACE_DEBUG((LM_INFO,
	     "(%P|%t) starting server at port %d\n",
	     _9901addr.get_port_number()));

  //  ACE_INET_Addr repo_addr(repo_port,repo_host.c_str());
  ACE_SOCK_Connector con;
  //  ACE_SOCK_Stream cli_stream ;
  ACE_Thread_Manager* mgr = ACE_Thread_Manager::instance();
//  if(con.connect(cli_stream,repo_addr)==-1){
//    ACE_ERROR_RETURN((LM_ERROR,
//		      "(%P|%t:%l) %p\n","connection failed"),0);
//  }else{
//    ACE_DEBUG((LM_DEBUG,
//	       "(%P|%t) connected to %s at port %d\n",repo_addr.get_host_name(),repo_addr.get_port_number()));
//  }
  /*connector side; do in a seperate thread;
   */
  if(mgr->spawn(fetch_step2,
		0,
		THR_DETACHED) == -1){
    ACE_ERROR ((LM_ERROR,
                "(%P|%t) %p\n",
                "spawn"));
  }
  /*
    run the accept loop ;
   */
  do{
    ACE_SOCK_Stream stream;
    if(_9901acceptor.accept(stream)== -1){
      ACE_ERROR_RETURN((LM_ERROR,
			"(%P|%t:%l) %p\n","accept failed"),0);
    }else{
      ACE_DEBUG((LM_DEBUG,
		 "(%P|%t:%l) connected to %s at port %d\n",_9901addr.get_host_name(),_9901addr.get_port_number()));
    }
    if(mgr->spawn(accept_step1,
		  reinterpret_cast<void *> (stream.get_handle()),
		  THR_DETACHED) == -1){
      ACE_ERROR ((LM_ERROR,
		  "(%P|%t) %p\n",
		  "spawn"));
    }
  }while(true);
  
  return 0;
}
开发者ID:jungu,项目名称:brokenseal,代码行数:65,代码来源:fence.cpp

示例2: if

int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  u_short port = argc > 1 ? ACE_OS::atoi (argv[1]) : ACE_DEFAULT_SERVER_PORT;
  ACE_TLI_Acceptor server;
  ACE_TLI_Stream new_stream;

  // Open the server and reuse the address if in use...
  if (server.open (ACE_INET_Addr (port), 1) == -1)
    ACE_OS::t_error ("server.open"), ACE_OS::exit (1);

  // Wait for a connection from a client.  This is an example of a
  // concurrent server.

  for (int count = 1; ; count++)
    {
      ACE_DEBUG ((LM_DEBUG,
                  "thread %t, blocking for accept #%d\n",
                  count));

      if (server.accept (new_stream) == -1)
        ACE_OS::t_error ("server.accept error");

      else if (thr_mgr.spawn (ACE_THR_FUNC (read_file),
                              (void *) new_stream.get_handle (),
                              THR_DETACHED | THR_BOUND) == -1)
        ACE_OS::perror ("can't create worker thread\n");
    }

  ACE_NOTREACHED (return 0);
}
开发者ID:DOCGroup,项目名称:ACE_TAO,代码行数:31,代码来源:ftp-server.cpp

示例3: get_opts

int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("s:c:"));
  int c = -1;
  const ACE_TCHAR *client_cmd = 0;

  while ((c = get_opts ()) != -1)
    switch (c)
      {
      case 'c':
        client_cmd = get_opts.opt_arg ();
        ACE_DEBUG ((LM_DEBUG, "Client argument: %s\n", client_cmd));
        break;
      case 's':
        server_cmd = get_opts.opt_arg ();
        ACE_DEBUG ((LM_DEBUG, "Server argument: %s\n", server_cmd));
        break;
      default:
        ACE_ERROR_RETURN ((LM_ERROR,
                           "Usage: collocation_test -s \"server opts\" -c \"client opts\""),
                          -1);
      }

  ACE_TCHAR cmd_line[1024];
  ACE_OS::strcpy (cmd_line, ACE_TEXT("client "));
  if (client_cmd != 0)
    ACE_OS::strcat (cmd_line, client_cmd);
  ACE_OS::strcat (cmd_line, ACE_TEXT(" -f ") THE_IOR);
  ACE_ARGV args (cmd_line);

  Barriers thread_barrier (2);

  int retv = 1;

  ACE_DEBUG ((LM_DEBUG,
              "\n \t IDL_Cubit: Collocation test \n\n"));

  ACE_Thread_Manager tm;
  tm.spawn (reinterpret_cast<ACE_THR_FUNC> (&svr_worker),
            &thread_barrier);
  thread_barrier.server_init_.wait ();
  ACE_OS::sleep (1);

  Cubit_Client cubit_client (1);
  // Make sure the server shuts itself down afterward.

  if (cubit_client.init (args.argc (), args.argv ()) == -1)
    return 1;
  else
    retv = cubit_client.run ();

  thread_barrier.client_fini_.wait ();
  tm.wait ();

  ACE_OS::unlink (THE_IOR);
  return retv;
}
开发者ID:asdlei00,项目名称:ACE,代码行数:58,代码来源:collocation_test.cpp

示例4: thread_test

int thread_test(int argc, char *argv[])
{
	ACE_Thread_Manager* pThMgr = ACE_Thread_Manager::instance();
	ACE_thread_t thId = 0;
	int ret = pThMgr->spawn(thread_func, "create thread"
		, THR_DETACHED|THR_SCOPE_SYSTEM
		, &thId);
	printf("thread_id=%d\n", thId);
	ret = pThMgr->join(thId);
	return ret;
}
开发者ID:walterfan,项目名称:snippets,代码行数:11,代码来源:waltertest.cpp

示例5:

int
ACE_TMAIN (int, ACE_TCHAR *[])
{
  // Message queue.
  ACE_Message_Queue<ACE_MT_SYNCH> msg_queue (max_queue);

  if (thr_mgr.spawn (ACE_THR_FUNC (producer), (void *) &msg_queue,
                         THR_NEW_LWP | THR_DETACHED) == -1)
    ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "spawn"), 1);

  // Wait for producer and consumer threads to exit.
  thr_mgr.wait ();
  return 0;
}
开发者ID:CCJY,项目名称:ACE,代码行数:14,代码来源:priority_buffer.cpp

示例6:

void TAO::Fault_Detector_i::start(ACE_Thread_Manager & threadManager)
{
  threadManager.spawn(thr_func, this);
}
开发者ID:OspreyHub,项目名称:ATCD,代码行数:4,代码来源:Fault_Detector_i.cpp

示例7: collectionAR

int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
    if (parse_args (argc, argv) == -1)
        return -1;

    ACE_Token_Proxy *A;  // Mutex *A*.
    ACE_Token_Proxy *B;  // Mutex *B*.
    ACE_Token_Proxy *R;  // *R*eader Lock.
    ACE_Token_Proxy *W;  // *W*riter Lock.

    // Depending on the command line arguments, we will create local or
    // remote tokens.  The names of the tokens are not important as long
    // as they are unique.
    if (remote)
    {
        ACE_Remote_Mutex::set_server_address (ACE_INET_Addr (server_port, server_host));
        A = new ACE_Remote_Mutex ("R Mutex A", 0, debug);
        B = new ACE_Remote_Mutex ("R Mutex B", 0, debug);
        R = new ACE_Remote_RLock ("R Reader Lock", 0, debug);
        W = new ACE_Remote_WLock ("R Writer Lock", 0, debug);
    }
    else
    {
        A = new ACE_Local_Mutex ("L Mutex A", 0, debug);
        B = new ACE_Local_Mutex ("L Mutex B", 0, debug);
        R = new ACE_Local_RLock ("L Reader Lock", 0, debug);
        W = new ACE_Local_WLock ("L Writer Lock", 0, debug);
    }

    // These collections will be treated as Tokens by the threads.
    ACE_Token_Collection collectionAR (debug, "A and Reader");
    ACE_Token_Collection collectionAW (debug, "A and Writer");
    ACE_Token_Collection collectionBR (debug, "B and Reader");

    // AR and BR can run concurrently.  Neither AR or BR can run when AW
    // is running.
    collectionAR.insert (*A);
    collectionAR.insert (*R);

    collectionAW.insert (*A);
    collectionAW.insert (*W);

    collectionBR.insert (*B);
    collectionBR.insert (*R);

    // Spawn off three threads.
    ACE_Thread_Manager *mgr = ACE_Thread_Manager::instance ();

    if (mgr->spawn (ACE_THR_FUNC (run_thread),
                    (void *) &collectionAR, THR_BOUND | THR_SUSPENDED) == -1)
        ACE_ERROR_RETURN ((LM_DEBUG, "%p\n", "spawn 1 failed"), -1);

    if (mgr->spawn (ACE_THR_FUNC (run_thread),
                    (void *) &collectionAW, THR_BOUND | THR_SUSPENDED) == -1)
        ACE_ERROR_RETURN ((LM_DEBUG, "%p\n", "spawn 2 failed"), -1);

    if (mgr->spawn (ACE_THR_FUNC (run_thread),
                    (void *) &collectionBR, THR_BOUND | THR_SUSPENDED) == -1)
        ACE_ERROR_RETURN ((LM_DEBUG, "%p\n", "spawn 3 failed"), -1);

#if ! defined (ACE_HAS_PTHREADS)
    if (mgr->resume_all () == -1)
        ACE_ERROR_RETURN ((LM_DEBUG, "%p\n", "resume failed"), -1);
#endif

    // Wait for all threads to exit.
    mgr->wait ();

    return 0;
}
开发者ID:asdlei00,项目名称:ACE,代码行数:71,代码来源:collection.cpp

示例8: timeout

int
ACE_TMAIN(int argc, ACE_TCHAR* argv[]){
  u_long priority_mask =
  ACE_LOG_MSG->priority_mask (ACE_Log_Msg::PROCESS);
  ACE_CLR_BITS (priority_mask,
		LM_DEBUG|LM_TRACE);
  ACE_LOG_MSG->priority_mask (priority_mask,
			      ACE_Log_Msg::PROCESS);


  ACE::set_handle_limit();
  ACE_Thread_Manager* mgr = ACE_Thread_Manager::instance();
  ACE_SOCK_Acceptor _987acceptor;
  ACE_INET_Addr _987addr(0x987);//2439
  
  if(_987acceptor.open(_987addr, 1) == -1){
    ACE_ERROR_RETURN((LM_ERROR,
		      "%p\n",
		      "open"),
		     1);
  }else if(_987acceptor.get_local_addr(_987addr) == -1){
    ACE_ERROR_RETURN ((LM_ERROR,
		       "%p\n",
		       "get_local_addr"),
		      1);
  }

  ACE_DEBUG((LM_INFO,
	     "(%P|%t) starting 987 server at port %d\n",
	     _987addr.get_port_number()));
  ACE_SOCK_Stream _str;

  ACE_Handle_Set _set;
  _set.set_bit(_987acceptor.get_handle());

  do{
    ACE_Time_Value timeout(ACE_DEFAULT_TIMEOUT);
    ACE_Handle_Set tmp = _set;
    int result = ACE_OS::select(ACE_Utils::truncate_cast<int> ((intptr_t) _987acceptor.get_handle()) +1,
				(fd_set *) tmp,
				0,
				0,
				NULL);
    if(result == -1)
      ACE_ERROR((LM_ERROR,
		 "(%P|%t) %p\n",
		 "select"));
    else if(result==0)
      ACE_DEBUG((LM_INFO,
		 "(%P|%t) select timed out\n"));
    else{
      if(tmp.is_set(_987acceptor.get_handle())){
	if(_987acceptor.accept(_str) == -1){
	  ACE_ERROR((LM_ERROR,
		     "%p\n",
		     "987 accept"));
	  continue;
	}else{
	  ACE_DEBUG((LM_INFO,
		     "(%P|%t: %l) spawning 987 server\n"));
	  if(mgr->spawn(process,
			reinterpret_cast<void*> (_str.get_handle()),
			THR_DETACHED) == -1){
	    ACE_ERROR((LM_ERROR,
		       "(%P|%t) %p\n",
		       "spawn"));
	  }
	}
      }
    }
  }while(true);

  return 0;
}
开发者ID:jungu,项目名称:brokenseal,代码行数:74,代码来源:logS.cpp


注:本文中的ACE_Thread_Manager::spawn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。