本文整理匯總了C++中ACE_THR_FUNC函數的典型用法代碼示例。如果您正苦於以下問題:C++ ACE_THR_FUNC函數的具體用法?C++ ACE_THR_FUNC怎麽用?C++ ACE_THR_FUNC使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ACE_THR_FUNC函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: ACE_TMAIN
int
ACE_TMAIN (int, ACE_TCHAR *[])
{
// Message list.
ACE_Message_Queue<ACE_MT_SYNCH> msg_queue;
if (ACE_Thread_Manager::instance ()->spawn
(ACE_THR_FUNC (producer),
(void *) &msg_queue,
THR_NEW_LWP | THR_DETACHED) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
"%p\n",
"spawn"),
1);
else if (ACE_Thread_Manager::instance ()->spawn
(ACE_THR_FUNC (consumer),
(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.
ACE_Thread_Manager::instance ()->wait ();
return 0;
}
示例2: spawn
static int
spawn (void)
{
// Create the synchronizer before spawning the child process/thread,
// to avoid race condition between the creation in the parent and
// use in the child.
ACE_NEW_RETURN (synchronizer,
SYNCHRONIZER ((unsigned int)0), // Locked by default...
-1);
#if !defined (ACE_LACKS_FORK)
switch (ACE_OS::fork (ACE_TEXT ("child")))
{
case -1:
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("(%P|%t) %p\n"),
ACE_TEXT ("fork failed")),
1);
/* NOTREACHED */
case 0:
parent ();
// Remove the semaphore.
synchronizer->remove ();
delete synchronizer;
break;
/* NOTREACHED */
default:
child ();
delete synchronizer;
break;
/* NOTREACHED */
}
#elif defined (ACE_HAS_THREADS)
if (ACE_Thread_Manager::instance ()->spawn
(ACE_THR_FUNC (child),
(void *) 0,
THR_NEW_LWP | THR_DETACHED) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("(%P|%t) %p\n"),
ACE_TEXT ("thread create failed")),
1);
else if (ACE_Thread_Manager::instance ()->spawn
(ACE_THR_FUNC (parent),
(void *) 0,
THR_NEW_LWP | THR_DETACHED) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("(%P|%t) %p\n"),
ACE_TEXT ("thread create failed")),
1);
ACE_Thread_Manager::instance ()->wait ();
delete synchronizer;
#else
ACE_UNUSED_ARG (synchronizer);
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("only one thread may be run in a process on this platform\n")),
1);
#endif /* ACE_HAS_THREADS */
return 0;
}
示例3: run_main
int
run_main (int, ACE_TCHAR *[])
{
ACE_START_TEST (ACE_TEXT ("Reactors_Test"));
#if defined (ACE_HAS_THREADS)
ACE_TEST_ASSERT (ACE_LOG_MSG->op_status () != -1);
thr_mgr = ACE_Thread_Manager::instance ();
ACE_Reactor reactor;
ACE_TEST_ASSERT (ACE_LOG_MSG->op_status () != -1);
Test_Task tt1[MAX_TASKS];
Test_Task tt2[MAX_TASKS];
// Activate all of the Tasks.
for (int i = 0; i < MAX_TASKS; i++)
{
tt1[i].open (ACE_Reactor::instance ());
tt2[i].open (&reactor);
}
// Spawn two threads each running a different reactor.
if (ACE_Thread_Manager::instance ()->spawn
(ACE_THR_FUNC (worker),
(void *) ACE_Reactor::instance (),
THR_BOUND | THR_DETACHED) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("spawn")),
-1);
else if (ACE_Thread_Manager::instance ()->spawn
(ACE_THR_FUNC (worker), (void *) &reactor,
THR_BOUND | THR_DETACHED) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("spawn")),
-1);
if (ACE_Thread_Manager::instance ()->wait () == -1)
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("wait")),
-1);
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("(%t) all threads are finished\n")));
#else
ACE_ERROR ((LM_INFO,
ACE_TEXT ("threads not supported on this platform\n")));
#endif /* ACE_HAS_THREADS */
ACE_END_TEST;
return 0;
}
示例4: ACE_TMAIN
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
if (argc != 2)
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("usage: pingpong <string>\n")),
-1);
ACE_LOG_MSG->open (argv[0]);
string_name = argv[1];
ACE_HANDLE handles[2];
//FUZZ: disable check_for_lack_ACE_OS
// Create a pipe and initialize the handles.
ACE_Pipe pipe (handles);
//FUZZ: enable check_for_lack_ACE_OS
#if defined (ACE_WIN32) || defined (CHORUS)
if (ACE_Thread::spawn (ACE_THR_FUNC (worker),
(void *) handles[0],
THR_DETACHED) == -1
|| ACE_Thread::spawn (ACE_THR_FUNC (worker),
(void *) handles[1],
THR_DETACHED) == -1)
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("%p\n%a"),
ACE_TEXT ("spawn"),
1));
barrier.wait ();
#else
pid_t pid = ACE_OS::fork (argv[0]);
if (pid == -1)
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("%p\n%a"),
ACE_TEXT ("fork"),
1));
run_svc (handles[pid == 0]);
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("(%P|%t) %n: shutting down tester\n")));
#endif /* ACE_WIN32 */
if (pipe.close () == -1)
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("close")));
return 0;
}
示例5: ACE_TMAIN
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);
}
示例6: run_main
int
run_main (int, ACE_TCHAR *[])
{
ACE_START_TEST (ACE_TEXT ("Priority_Buffer_Test"));
#if defined (ACE_HAS_THREADS)
// Message queue.
ACE_Message_Queue<ACE_MT_SYNCH> msg_queue (max_queue);
if (ACE_Thread_Manager::instance ()->spawn
(ACE_THR_FUNC (producer),
(void *) &msg_queue,
THR_NEW_LWP | THR_DETACHED) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("spawn")),
1);
// Wait for producer and consumer threads to exit.
ACE_Thread_Manager::instance ()->wait ();
#else
ACE_ERROR ((LM_INFO,
ACE_TEXT ("threads not supported on this platform\n")));
#endif /* ACE_HAS_THREADS */
ACE_END_TEST;
return 0;
}
示例7: spawn
static void
spawn (ACE_CLASSIX_Port_Core* theServer)
{
// create a port for the server
ACE_DEBUG ((LM_DEBUG, "(%P|%t) starting server at port %d\n",
theServer->get_handle ()));
// activate server
server_handler handler(TEST_STAMP, *theServer);
handler.open(); // make the server active
// activate clients
// make sure
// - we don't let client send messages before the event loop is running
ACE_Barrier wait(MAX_TEST_CLIENTS);
client_arg data;
data.server = theServer;
data.wait = &wait;
ACE_DEBUG ((LM_DEBUG, "(%t) starting clients\n"));
if (ACE_Thread_Manager::instance ()->spawn_n
(MAX_TEST_CLIENTS,
ACE_THR_FUNC (client),
(void *) &data,
THR_BOUND | THR_DETACHED) == -1)
ACE_ERROR ((LM_ERROR, "(%P|%t) %p\n%a", "spawn failed"));
// handle event
ACE_DEBUG((LM_DEBUG, "(%t)run event loop\n"));
ACE_Reactor::run_event_loop();
// wait until all server has completed
ACE_Thread_Manager::instance()->wait_task(&handler);
}
示例8: ACE_TMAIN
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
// The Service_Config must be the first object defined in main...
ACE_Service_Config daemon (argv[0]);
int threads = argc > 1 ? ACE_OS::atoi (argv[1]) : 4;
intptr_t count = argc > 2 ? ACE_OS::atoi (argv[2]) : 10000;
// Register a signal handler.
ACE_Sig_Action sa ((ACE_SignalHandler) (handler), SIGINT);
ACE_UNUSED_ARG (sa);
#if defined (ACE_HAS_THREADS)
if (ACE_Thread_Manager::instance ()->spawn_n (threads,
ACE_THR_FUNC (&worker),
reinterpret_cast<void *> (count),
THR_BOUND | THR_DETACHED) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
"%p\n",
"ACE_Thread_Manager::spawn_n"),
-1);
ACE_Thread_Manager::instance ()->wait ();
#else
worker ((void *) count);
#endif /* ACE_HAS_THREADS */
return 0;
}
示例9: peer2
static void *
peer2 (void *)
{
ACE_UPIPE_Acceptor acc (addr);
ACE_UPIPE_Stream s_stream;
// Spawn a peer1 thread.
if (ACE_Thread_Manager::instance ()->spawn (ACE_THR_FUNC (peer1),
(void *) 0,
THR_NEW_LWP | THR_DETACHED) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
"%p\n",
"spawn"),
0);
ACE_DEBUG ((LM_DEBUG,
"(%t) peer2 starting accept\n"));
if (acc.accept (s_stream) == -1)
ACE_ERROR ((LM_ERROR,
"(%t) ACE_UPIPE_Acceptor.accept failed\n"));
ACE_Message_Block *mb = 0;
if (s_stream.recv (mb) == -1)
ACE_ERROR ((LM_ERROR,
"(%t) peer2 recv failed\n"));
ACE_DEBUG ((LM_DEBUG, "(%t) peer2 recv is \"%s\"\n",
mb->rd_ptr ()));
mb->wr_ptr (mb->rd_ptr ());
mb->copy ("thanks", 7);
if (s_stream.send (mb) == -1)
ACE_ERROR ((LM_ERROR,
"(%t) peer2 send failed\n"));
char s_buf[42];
ACE_DEBUG ((LM_DEBUG,
"(%t) peer2 sleeping on recv\n"));
if (s_stream.recv (s_buf, sizeof s_buf) == -1)
ACE_ERROR ((LM_ERROR,
"(%t) peer2 recv failed\n"));
else
ACE_DEBUG ((LM_DEBUG,
"(%t) peer2 received buffer with \"%s\"\n",
s_buf));
ACE_OS::strcpy (s_buf,
"this is the peer2 response!");
if (s_stream.send (s_buf, 30) == -1)
ACE_ERROR ((LM_ERROR,
"(%t) peer2 send failed\n"));
s_stream.close ();
return 0;
}
示例10: run_main
int
run_main (int argc, ACE_TCHAR *argv[])
{
ACE_START_TEST (ACE_TEXT ("Reactor_Exceptions_Test"));
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("Starting tracing\n")));
u_short port = argc > 1 ? ACE_OS::atoi (argv[1]) : ACE_DEFAULT_SERVER_PORT;
ACE_INET_Addr local_addr (port);
ACE_INET_Addr remote_addr (port, ACE_LOCALHOST, PF_INET);
ACE_Reactor reactor (new My_Reactor, true);
ACE_Reactor::instance (&reactor);
ACE_Thread_Manager *thr_mgr = ACE_Thread_Manager::instance ();
{
// Make sure handler gets cleaned up before reactor by putting it in its
// own scope
My_Handler handler (local_addr);
if (ACE_Reactor::instance ()->register_handler
(&handler,
ACE_Event_Handler::READ_MASK) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("register_handler")),
-1);
#if defined (ACE_HAS_THREADS)
thr_mgr->spawn (ACE_THR_FUNC (worker));
#else
// Need to figure out how to implement this test.
ACE_ERROR ((LM_INFO,
ACE_TEXT ("threads not supported on this platform\n")));
#endif /* ACE_HAS_THREADS */
ACE_SOCK_Dgram dgram (ACE_sap_any_cast (ACE_INET_Addr &), PF_INET);
for (size_t i = 0; i < ACE_MAX_ITERATIONS; i++)
dgram.send (ACE_TEXT ("Hello"),
sizeof (ACE_TEXT ("Hello")),
remote_addr);
// Barrier to wait for the other thread to return.
thr_mgr->wait ();
handler.close ();
dgram.close ();
}
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT (" (%t) exiting main\n")));
ACE_END_TEST;
return 0;
}
示例11: Transcode
void Transcode(CStdString &file)
{
OrkLogManager::Instance()->Initialize();
ObjectFactory::GetSingleton()->Initialize();
ConfigManager::Instance()->Initialize();
std::list<ACE_DLL> pluginDlls;
LoadPlugins(pluginDlls);
// Register in-built filters
FilterRef filter(new AlawToPcmFilter());
FilterRegistry::instance()->RegisterFilter(filter);
filter.reset(new UlawToPcmFilter());
FilterRegistry::instance()->RegisterFilter(filter);
filter.reset(new GsmToPcmFilter());
FilterRegistry::instance()->RegisterFilter(filter);
filter.reset(new IlbcToPcmFilter());
FilterRegistry::instance()->RegisterFilter(filter);
filter.reset(new AudioGainFilter());
FilterRegistry::instance()->RegisterFilter(filter);
filter.reset(new G722ToPcmFilter());
FilterRegistry::instance()->RegisterFilter(filter);
filter.reset(new SpeexDecoder() );
FilterRegistry::instance()->RegisterFilter(filter);
filter.reset(new G721CodecDecoder());
FilterRegistry::instance()->RegisterFilter(filter);
// Register in-built tape processors and build the processing chain
BatchProcessing::Initialize();
Reporting::Initialize();
TapeFileNaming::Initialize();
if (!ACE_Thread_Manager::instance()->spawn(ACE_THR_FUNC(BatchProcessing::ThreadHandler)))
{
LOG4CXX_INFO(LOG.rootLog, CStdString("Failed to create batch processing thread"));
}
// Transmit the tape to the BatchProcessing
CStdString ProcessorName("BatchProcessing");
TapeProcessorRef bp = TapeProcessorRegistry::instance()->GetNewTapeProcessor(ProcessorName);
CStdString portName("SinglePort");
AudioTapeRef tape(new AudioTape(portName, file));
bp->AddAudioTape(tape);
// Make sure it stops after processing
tape.reset();
bp->AddAudioTape(tape);
// Wait for completion
while(!Daemon::Singleton()->IsStopping())
{
ACE_OS::sleep(1);
}
}
示例12: run_main
int
run_main (int, ACE_TCHAR *[])
{
ACE_START_TEST (ACE_TEXT ("TSS_Test"));
#if defined (ACE_HAS_THREADS)
Errno::allocate_lock ();
const u_int threads = ACE_MAX_THREADS;
// Dynamically allocate TSS_Error so that we can control when it
// gets deleted. Specifically, we need to delete it before the
// ACE_Object_Manager destroys the ACE_Allocator. That's because
// deletion of TSS_Error causes the internal structures of
// ACE_TSS_Cleanup to be modified, and which in turn uses
// ACE_Allocator.
ACE_NEW_RETURN (tss_error, ACE_TSS<Errno>, 1);
// Similarly, dynamically allocate u.
ACE_NEW_RETURN (u, ACE_TSS<ACE_TSS_Type_Adapter<u_int> >, 1);
int iterations = ITERATIONS;
if (ACE_Thread_Manager::instance ()->spawn_n
(threads,
ACE_THR_FUNC (worker),
&iterations,
THR_BOUND) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("%p\n"), ACE_TEXT ("spawn_n")), 1);
ACE_Thread_Manager::instance ()->wait ();
delete u;
delete tss_error;
Errno::deallocate_lock ();
if (Errno::created () != Errno::deleted ())
{
//@@TODO: this should probably be promoted to an error rather than just a
// warning.
ACE_ERROR ((LM_DEBUG,
ACE_TEXT ("(%P|%t) Warning: Number created (%d) != number deleted (%d)\n"),
Errno::created (),
Errno::deleted ()
));
}
#else /* ACE_HAS_THREADS */
ACE_ERROR ((LM_INFO,
ACE_TEXT ("threads are not supported on this platform\n")));
#endif /* ACE_HAS_THREADS */
ACE_END_TEST;
return errors ? -1 : 0;
}
示例13: run_main
int run_main (int argc, ACE_TCHAR *argv[])
{
ACE_START_TEST (ACE_TEXT ("Manual_Event_Test"));
#if defined (ACE_HAS_THREADS)
parse_args (argc, argv);
if (ACE_Thread_Manager::instance ()->spawn_n
(static_cast<size_t> (n_workers),
ACE_THR_FUNC (worker),
0,
THR_NEW_LWP) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("spawn_n")),
1);
// gives all workers chance to start
ACE_OS::sleep (5);
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("sending pulse ()\n")));
// Release the all workers.
if (evt.pulse () == -1)
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("pulse")),
1);
// Wait 2 sec
ACE_OS::sleep (2);
//FUZZ: disable check_for_lack_ACE_OS
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("sending signal ()\n")));
//FUZZ: enable check_for_lack_ACE_OS
// Signal
if (evt.signal () == -1)
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("signal")),
1);
ACE_Thread_Manager::instance ()->wait ();
#else
ACE_UNUSED_ARG (argc);
ACE_UNUSED_ARG (argv);
ACE_ERROR ((LM_INFO,
ACE_TEXT ("Threads not supported on this platform\n")));
#endif /* ACE_HAS_THREADS */
ACE_END_TEST;
return test_result;
}
示例14: run_main
int
run_main (int, ACE_TCHAR *[])
{
ACE_START_TEST (ACE_TEXT ("UPIPE_SAP_Test"));
#if defined (ACE_HAS_THREADS) && \
(defined (ACE_HAS_STREAM_PIPES) || defined (ACE_HAS_WIN32_NAMED_PIPES))
ACE_UPIPE_Acceptor acc (addr);
// Spawn a acceptor thread.
if (ACE_Thread_Manager::instance ()->spawn (ACE_THR_FUNC (acceptor),
(void *) &acc,
THR_NEW_LWP,
0) == -1)
ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("spawn")), 1);
// Spawn a connector thread.
if (ACE_Thread_Manager::instance ()->spawn (ACE_THR_FUNC (connector),
(void *) 0,
THR_NEW_LWP,
0) == -1)
ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("spawn")), 1);
ACE_Thread_Manager::instance ()->wait ();
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) joined with acceptor thread\n")));
// Close the acceptor
acc.close ();
#else
#if !defined (ACE_HAS_THREADS)
ACE_ERROR ((LM_INFO, ACE_TEXT ("threads not supported on this platform\n")));
#else
ACE_ERROR ((LM_INFO, ACE_TEXT ("UPIPE is not supported on this platform\n")));
#endif /* !defined (ACE_HAS_THREADS) */
#endif /* ACE_HAS_THREADS && (ACE_HAS_STREAM_PIPES || ACE_HAS_WIN32_NAMED_PIPES) */
ACE_END_TEST;
return 0;
}
示例15: run_main
int run_main (int argc, ACE_TCHAR *argv[])
{
ACE_START_TEST (ACE_TEXT ("Reader_Writer_Test"));
#if defined (ACE_HAS_THREADS)
parse_args (argc, argv);
current_readers = 0; // Possibly already done
current_writers = 0; // Possibly already done
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT (" (%t) main thread starting\n")));
if (ACE_Thread_Manager::instance ()->spawn_n (n_readers,
ACE_THR_FUNC (reader),
0,
THR_NEW_LWP) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("spawn_n")), 1);
else if (ACE_Thread_Manager::instance ()->spawn_n (n_writers,
ACE_THR_FUNC (writer),
0,
THR_NEW_LWP) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("spawn_n")), 1);
ACE_Thread_Manager::instance ()->wait ();
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT (" (%t) exiting main thread\n")));
#else
ACE_UNUSED_ARG (argc);
ACE_UNUSED_ARG (argv);
ACE_ERROR ((LM_INFO,
ACE_TEXT ("threads not supported on this platform\n")));
#endif /* ACE_HAS_THREADS */
ACE_END_TEST;
return 0;
}