本文整理汇总了C++中spawn_thread函数的典型用法代码示例。如果您正苦于以下问题:C++ spawn_thread函数的具体用法?C++ spawn_thread怎么用?C++ spawn_thread使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了spawn_thread函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: do_threads
void do_threads(SSL_CTX *s_ctx, SSL_CTX *c_ctx)
{
SSL_CTX *ssl_ctx[2];
thread_id thread_ctx[MAX_THREAD_NUMBER];
int i;
ssl_ctx[0]=s_ctx;
ssl_ctx[1]=c_ctx;
for (i=0; i<thread_number; i++)
{
thread_ctx[i] = spawn_thread((thread_func)ndoit,
NULL, B_NORMAL_PRIORITY, (void *)ssl_ctx);
resume_thread(thread_ctx[i]);
}
printf("waiting...\n");
for (i=0; i<thread_number; i++)
{
status_t result;
wait_for_thread(thread_ctx[i], &result);
}
printf("beos threads done (%d,%d)\n",
s_ctx->references,c_ctx->references);
}
示例2: PRINT
thread_id
BUrlRequest::Run()
{
// Thread already running
if (fRunning) {
PRINT(("BUrlRequest::Run() : Oops, already running ! "
"[urlProtocol=%p]!\n", this));
return fThreadId;
}
fThreadId = spawn_thread(BUrlRequest::_ThreadEntry, fThreadName,
B_NORMAL_PRIORITY, this);
if (fThreadId < B_OK)
return fThreadId;
fRunning = true;
status_t launchErr = resume_thread(fThreadId);
if (launchErr < B_OK) {
PRINT(("BUrlRequest::Run() : Failed to resume thread %" B_PRId32 "\n",
fThreadId));
return launchErr;
}
return fThreadId;
}
示例3: BVolumeRoster
status_t QueryMenu::SetPredicate(const char *expr, BVolume *volume)
{
status_t status;
// Set the volume
if (volume == NULL)
{
BVolume bootVolume;
BVolumeRoster().GetBootVolume(&bootVolume);
if ( (status = fQuery->SetVolume(&bootVolume)) != B_OK)
return status;
}
else if ((status = fQuery->SetVolume(volume)) != B_OK)
return status;
if ((status = fQuery->SetPredicate(expr)) < B_OK)
return status;
// Force query thread to exit if still running
fCancelQuery = true;
fQueryLock.Lock();
// Remove all existing menu items (if any... )
RemoveEntries();
fQueryLock.Unlock();
// Resolve Query/Build Menu in seperate thread
thread_id thread;
thread = spawn_thread(query_thread, "query menu thread", B_NORMAL_PRIORITY, this);
return resume_thread(thread);
}
示例4: resume_thread
KeepAlive::KeepAlive(PortTalker *port_talker) {
_keep_alive_thread_id = -1;
_port_talker = port_talker;
// Spawn listener thread (communication from remote machine)
resume_thread(_keep_alive_thread_id = spawn_thread(KeepAlive::_SpawnKeepAliveThread, "keep_alive", B_NORMAL_PRIORITY, this));
}
示例5: autolock
status_t
PowerStatusDriverInterface::StartWatching(BHandler* target)
{
BAutolock autolock(fListLocker);
status_t status = Monitor::StartWatching(target);
if (status != B_OK)
return status;
if (fThread > 0)
return B_OK;
fThread = spawn_thread(&_ThreadWatchPowerFunction, "PowerStatusThread",
B_LOW_PRIORITY, this);
if (fThread >= 0) {
fWaitSem = create_sem(0, "power status wait");
atomic_set(&fIsWatching, 1);
status = resume_thread(fThread);
} else
return fThread;
if (status != B_OK && fWatcherList.CountItems() == 0) {
atomic_set(&fIsWatching, 0);
delete_sem(fWaitSem);
fThread = -1;
fWaitSem = -1;
}
return status;
}
示例6: spawn_thread
void
LJEventEditor::GetItem()
{
thread_id get_event_thread = spawn_thread(get_event,
"EventEditor::GetEvent", B_NORMAL_PRIORITY, this);
resume_thread(get_event_thread);
}
示例7: _l
status_t AmInputQueue::StartPerforming()
{
BAutolock _l(mLock);
status_t result = B_ERROR;
// Start up record thread.
if (mPerformLock.Lock()) {
mPerformAvail = create_sem(0, "AmInputQueue Perform Avail");
if (mPerformAvail >= B_OK) {
mPerformThread = spawn_thread(PerformThreadEntry, "AmInputQueue Performer",
B_REAL_TIME_PRIORITY, this);
if (mPerformThread >= B_OK) {
resume_thread(mPerformThread);
result = B_OK;
} else {
result = mPerformThread;
delete_sem(mPerformAvail);
mPerformAvail = B_BAD_SEM_ID;
}
} else {
result = mPerformAvail;
}
mPerformLock.Unlock();
}
return result;
}
示例8: BLooper
FractalEngine::FractalEngine(BHandler* parent, BLooper* looper)
:
BLooper("FractalEngine"),
fWidth(0), fHeight(0),
fRenderBuffer(NULL),
fRenderBufferLen(0),
fSubsampling(2),
fMessenger(parent, looper),
fIterations(1024),
fColorset(Colorset_Royal)
{
fDoSet = &FractalEngine::DoSet_Mandelbrot;
fRenderSem = create_sem(0, "RenderSem");
fRenderStoppedSem = create_sem(0, "RenderStopped");
system_info info;
get_system_info(&info);
fThreadCount = info.cpu_count;
if (fThreadCount > MAX_RENDER_THREADS)
fThreadCount = MAX_RENDER_THREADS;
for (uint8 i = 0; i < fThreadCount; i++) {
fRenderThreads[i] = spawn_thread(&FractalEngine::RenderThread,
BString().SetToFormat("RenderThread%d", i).String(),
B_NORMAL_PRIORITY, this);
resume_thread(fRenderThreads[i]);
}
}
示例9: BWindowScreen
MacScreen::MacScreen(const BeOS_monitor_desc& monitor, const char *name, int mode_bit, status_t *error)
: BWindowScreen(name, 1 << mode_bit, error), tick_thread(-1)
, monitor(monitor)
{
// Set all variables
frame_backup = NULL;
palette_changed = false;
screen_active = false;
first_time = true;
quitting = false;
// Set relative mouse mode
ADBSetRelMouseMode(true);
// Create view to get mouse events
main_view = new BView(Frame(), NULL, B_FOLLOW_NONE, 0);
AddChild(main_view);
// Start 60Hz interrupt
tick_thread_active = true;
tick_thread = spawn_thread(tick_func, "Polling sucks...", B_DISPLAY_PRIORITY, this);
resume_thread(tick_thread);
// Add filter for keyboard and mouse events
BMessageFilter *filter = new BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE, filter_func);
AddCommonFilter(filter);
}
示例10: locker
bool
MessageLooper::Run()
{
BAutolock locker(this);
fQuitting = false;
char name[B_OS_NAME_LENGTH];
_GetLooperName(name, sizeof(name));
// Spawn our message-monitoring thread
fThread = spawn_thread(_message_thread, name, B_DISPLAY_PRIORITY, this);
if (fThread < B_OK) {
fQuitting = true;
return false;
}
if (resume_thread(fThread) != B_OK) {
fQuitting = true;
kill_thread(fThread);
fThread = -1;
return false;
}
return true;
}
示例11: setup_server
void
setup_server()
{
sockaddr_in address;
memset(&address, 0, sizeof(address));
address.sin_len = sizeof(sockaddr_in);
address.sin_family = AF_INET;
address.sin_port = htons(1024);
address.sin_addr.s_addr = INADDR_ANY;
status_t status = socket_bind(gServerSocket, (struct sockaddr*)&address,
sizeof(struct sockaddr));
if (status < B_OK) {
fprintf(stderr, "tcp_tester: cannot bind server: %s\n", strerror(status));
exit(1);
}
status = socket_listen(gServerSocket, 40);
if (status < B_OK) {
fprintf(stderr, "tcp_tester: server cannot listen: %s\n",
strerror(status));
exit(1);
}
thread_id serverThread = spawn_thread(server_thread, "server",
B_NORMAL_PRIORITY, NULL);
if (serverThread < B_OK) {
fprintf(stderr, "tcp_tester: cannot start server: %s\n",
strerror(serverThread));
exit(1);
}
resume_thread(serverThread);
}
示例12: main
int
main()
{
status_t s;
ssize_t size;
int32 code;
id = create_port(1, "test port");
printf("created port %ld\n", id);
s = write_port(id, 0x1234, data, 10);
printf("write port result 0x%08lx (%s)\n", s, strerror(s));
size = read_port(id, &code, data, sizeof(data));
printf("read port code %lx, size %ld (0x%08lx) (%s)\n", code, size, size, strerror(size));
printf("port_buffer_size should block for 5 seconds now, as port is empty\n");
thread_id thread = spawn_thread(test_thread, "test thread", B_NORMAL_PRIORITY, NULL);
resume_thread(thread);
snooze(5000000);
printf("write port...\n");
s = write_port(id, 0x5678, data, 20);
printf("write port result 0x%08lx (%s)\n", s, strerror(s));
printf("waiting for thread to terminate\n");
wait_for_thread(thread, &s);
return 0;
}
示例13: spawn_thread
// _InitServerInfoConnectionListener
status_t
NetFSServer::_InitServerInfoConnectionListener()
{
// spawn the listener thread
fServerInfoConnectionListener = spawn_thread(
&_ServerInfoConnectionListenerEntry,
"server info connection listener", B_NORMAL_PRIORITY, this);
if (fServerInfoConnectionListener < 0)
return fServerInfoConnectionListener;
// create a listener socket
fServerInfoConnectionListenerSocket = socket(AF_INET, SOCK_STREAM, 0);
if (fServerInfoConnectionListenerSocket < 0)
return errno;
// bind it to the port
sockaddr_in addr;
addr.sin_family = AF_INET;
addr.sin_port = htons(kDefaultServerInfoPort);
addr.sin_addr.s_addr = INADDR_ANY;
if (bind(fServerInfoConnectionListenerSocket, (sockaddr*)&addr,
sizeof(addr)) < 0) {
return errno;
}
// start listening
if (listen(fServerInfoConnectionListenerSocket, 5) < 0)
return errno;
return B_OK;
}
示例14: this_team
sptr<IProcess> BProcess::Spawn(const SString& name, const SValue& env, uint32_t flags)
{
#if BINDER_DEBUG_LIB
(void)env;
(void)flags;
team_id teamid = this_team()+atomic_add(&nextFakeProcessIDDelta,1);
bout << "spawning pretend team " << teamid << endl;
SysHandle thid = spawn_thread((thread_entry)pretend_team,"pretend_team",B_NORMAL_PRIORITY,(void *)teamid);
ErrFatalErrorIf(thid < 0, "could not spawn pretend_team");
sptr<IProcess> team
= IProcess::AsInterface(SLooper::GetRootObject(thid, teamid));
ErrFatalErrorIf(team == NULL, "pretend_team gave us a root object that wasn't an IProcess");
#else
SString fullName("/binder_team");
mkdir(fullName.String(), S_IRWXU|S_IRWXG|S_IRWXO);
fullName += "/";
if (name != "") fullName += name;
else fullName += "anonymous";
symlink("/system/servers/remote_place", fullName.String());
sptr<IBinder> teamBinder = SpawnFile(fullName, env, flags);
sptr<IProcess> team = IProcess::AsInterface(teamBinder);
ErrFatalErrorIf(team == NULL && teamBinder != NULL, "remote_place did not publish an IProcess");
#endif // BINDER_DEBUG_LIB
return team;
}
示例15: TRACE
void
VideoProducer::_HandleStart(bigtime_t performanceTime)
{
// Start producing frames, even if the output hasn't been connected yet.
TRACE("_HandleStart(%Ld)\n", performanceTime);
if (fRunning) {
TRACE("_HandleStart: Node already started\n");
return;
}
fFrame = 0;
fFrameBase = 0;
fPerformanceTimeBase = performanceTime;
fFrameSync = create_sem(0, "frame synchronization");
if (fFrameSync < B_OK)
return;
fThread = spawn_thread(_FrameGeneratorThreadEntry, "frame generator",
B_NORMAL_PRIORITY, this);
if (fThread < B_OK) {
delete_sem(fFrameSync);
return;
}
resume_thread(fThread);
fRunning = true;
return;
}