本文整理汇总了C++中setThreadName函数的典型用法代码示例。如果您正苦于以下问题:C++ setThreadName函数的具体用法?C++ setThreadName怎么用?C++ setThreadName使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setThreadName函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: setThreadName
bool setThreadName(pthread_t pid, StringPiece name) {
#if _WIN32
static_assert(
sizeof(unsigned int) == sizeof(std::thread::id),
"This assumes std::thread::id is a thin wrapper around "
"the thread id as an unsigned int, but that doesn't appear to be true.");
// std::thread::id is a thin wrapper around an integral thread id,
// so just stick the ID in.
unsigned int tid = pthread_getw32threadid_np(pid);
std::thread::id id;
std::memcpy(&id, &tid, sizeof(id));
return setThreadName(id, name);
#else
static_assert(
std::is_same<pthread_t, std::thread::native_handle_type>::value,
"This assumes that the native handle type is pthread_t");
static_assert(
sizeof(std::thread::native_handle_type) == sizeof(std::thread::id),
"This assumes std::thread::id is a thin wrapper around "
"std::thread::native_handle_type, but that doesn't appear to be true.");
// In most implementations, std::thread::id is a thin wrapper around
// std::thread::native_handle_type, which means we can do unsafe things to
// extract it.
std::thread::id id;
std::memcpy(static_cast<void*>(&id), &pid, sizeof(id));
return setThreadName(id, name);
#endif
}
开发者ID:JacobMao,项目名称:folly,代码行数:29,代码来源:ThreadName.cpp
示例2: setThreadName
AREXPORT
ArRecurrentTask::ArRecurrentTask()
{
setThreadName("ArRecurrentTask");
running = go_req = killed = false;
create(); // create the thread
}
开发者ID:eilo,项目名称:Evolucion-Artificial-y-Robotica-Autonoma-en-Robots-Pioneer-P3-DX,代码行数:7,代码来源:ArRecurrentTask.cpp
示例3: lk
Status TransportLayerASIO::start() {
stdx::lock_guard<stdx::mutex> lk(_mutex);
_running.store(true);
// If we're in async mode then the ServiceExecutor will handle calling run_one() in a pool
// of threads. Otherwise we need a thread to just handle the async_accept calls.
if (!_listenerOptions.async) {
_listenerThread = stdx::thread([this] {
setThreadName("listener");
while (_running.load()) {
try {
_ioContext->run();
_ioContext->reset();
} catch (...) {
severe() << "Uncaught exception in the listener: " << exceptionToStatus();
fassertFailed(40491);
}
}
});
}
for (auto& acceptor : _acceptors) {
acceptor.listen();
_acceptConnection(acceptor);
}
return Status::OK();
}
开发者ID:vnvizitiu,项目名称:mongo,代码行数:28,代码来源:transport_layer_asio.cpp
示例4: setThreadName
void MetricsTransmitter::run()
{
const auto & config = context.getConfigRef();
auto interval = config.getInt(config_name + ".interval", 60);
const std::string thread_name = "MericsTrns " + std::to_string(interval) + "s";
setThreadName(thread_name.c_str());
const auto get_next_time = [](size_t seconds)
{
/// To avoid time drift and transmit values exactly each interval:
/// next time aligned to system seconds
/// (60s -> every minute at 00 seconds, 5s -> every minute:[00, 05, 15 ... 55]s, 3600 -> every hour:00:00
return std::chrono::system_clock::time_point(
(std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()) / seconds) * seconds
+ std::chrono::seconds(seconds));
};
std::vector<ProfileEvents::Count> prev_counters(ProfileEvents::end());
std::unique_lock lock{mutex};
while (true)
{
if (cond.wait_until(lock, get_next_time(interval), [this] { return quit; }))
break;
transmit(prev_counters);
}
}
开发者ID:chipitsine,项目名称:ClickHouse,代码行数:30,代码来源:MetricsTransmitter.cpp
示例5: setThreadName
void ofxThreadedYouTubeVideo::threadedFunction()
{
setThreadName("ofxThreadedYouTubeVideo " + ofToString(thread.get_id()));
while( isThreadRunning() ) {
ofYouTubeLoaderEntry entry;
while( urls_to_load.receive(entry) ) {
if(!getNewURL(entry)) {
ofLogError("ofxThreadedYouTubeVideo") << "couldn't load url: \"" << entry.input_url << "\"";
//get another random video and try again
loadYouTubeURL("",entry.id);
}
else {
cout << "ofxThreadedYouTubeVideo got video url: " << entry.url << endl;
ofVideoPlayer* vid = new ofVideoPlayer();
vid->setUseTexture(false);
vid->load(entry.url);
ofxYouTubeURLEvent e = ofxYouTubeURLEvent(entry.url, entry.id,vid);
ofNotifyEvent(youTubeURLEvent, e, this);
}
}
} //is thread running
}
开发者ID:pierrep,项目名称:ofxThreadedYouTubeVideo,代码行数:29,代码来源:ofxThreadedYouTubeVideo.cpp
示例6: setThreadName
void CClient::waitForMoveAndSend(PlayerColor color)
{
try
{
setThreadName("CClient::waitForMoveAndSend");
assert(vstd::contains(battleints, color));
BattleAction ba = battleints[color]->activeStack(gs->curB->battleGetStackByID(gs->curB->activeStack, false));
if(ba.actionType != Battle::CANCEL)
{
logNetwork->traceStream() << "Send battle action to server: " << ba;
MakeAction temp_action(ba);
sendRequest(&temp_action, color);
}
return;
}
catch(boost::thread_interrupted&)
{
logNetwork->debugStream() << "Wait for move thread was interrupted and no action will be send. Was a battle ended by spell?";
return;
}
catch(...)
{
handleException();
return;
}
logNetwork->errorStream() << "We should not be here!";
}
开发者ID:argarak,项目名称:vcmi,代码行数:27,代码来源:Client.cpp
示例7: setThreadName
void AsynchronousBlockInputStream::next()
{
ready.reset();
pool.schedule([this, thread_group = CurrentThread::getGroup()] ()
{
CurrentMetrics::Increment metric_increment{CurrentMetrics::QueryThread};
try
{
if (first)
setThreadName("AsyncBlockInput");
/// AsynchronousBlockInputStream is used in Client which does not create queries and thread groups
if (thread_group)
CurrentThread::attachToIfDetached(thread_group);
}
catch (...)
{
exception = std::current_exception();
ready.set();
return;
}
calculate();
});
}
开发者ID:greck2908,项目名称:ClickHouse,代码行数:27,代码来源:AsynchronousBlockInputStream.cpp
示例8: setThreadName
int CConsoleHandler::run()
{
setThreadName("CConsoleHandler::run");
//disabling sync to make in_avail() work (othervice always returns 0)
std::ios::sync_with_stdio(false);
std::string buffer;
while ( std::cin.good() )
{
#ifndef _WIN32
//check if we have some unreaded symbols
if (std::cin.rdbuf()->in_avail())
{
if ( getline(std::cin, buffer).good() )
if ( cb && *cb )
(*cb)(buffer);
}
else
boost::this_thread::sleep(boost::posix_time::millisec(100));
boost::this_thread::interruption_point();
#else
std::getline(std::cin, buffer);
if ( cb && *cb )
(*cb)(buffer);
#endif
}
return -1;
}
开发者ID:lightsgoout,项目名称:vcmi,代码行数:29,代码来源:CConsoleHandler.cpp
示例9: LOG
// Background object can be only be destroyed after jobBody() ran
void BackgroundJob::jobBody( boost::shared_ptr<JobStatus> status ) {
LOG(1) << "BackgroundJob starting: " << name() << endl;
{
scoped_lock l( status->m );
massert( 13643 , mongoutils::str::stream() << "backgroundjob already started: " << name() , status->state == NotStarted );
status->state = Running;
}
const string threadName = name();
if( ! threadName.empty() )
setThreadName( threadName.c_str() );
try {
run();
}
catch ( std::exception& e ) {
log( LL_ERROR ) << "backgroundjob " << name() << "error: " << e.what() << endl;
}
catch(...) {
log( LL_ERROR ) << "uncaught exception in BackgroundJob " << name() << endl;
}
{
scoped_lock l( status->m );
status->state = Done;
status->finished.notify_all();
}
if( status->deleteSelf )
delete this;
}
开发者ID:Desartstudio,项目名称:mongo-nonx86,代码行数:32,代码来源:background.cpp
示例10: name
void BackgroundJob::jobBody() {
const string threadName = name();
if (!threadName.empty()) {
setThreadName(threadName);
}
LOG(1) << "BackgroundJob starting: " << threadName;
try {
run();
} catch (const std::exception& e) {
error() << "backgroundjob " << threadName << " exception: " << redact(e.what());
throw;
}
// We must cache this value so that we can use it after we leave the following scope.
const bool selfDelete = _selfDelete;
{
// It is illegal to access any state owned by this BackgroundJob after leaving this
// scope, with the exception of the call to 'delete this' below.
stdx::unique_lock<stdx::mutex> l(_status->mutex);
_status->state = Done;
_status->done.notify_all();
}
if (selfDelete)
delete this;
}
开发者ID:DINKIN,项目名称:mongo,代码行数:29,代码来源:background.cpp
示例11: invariant
/**
* This must be called whenever a new thread is started, so that active threads can be tracked
* so each thread has a Client object in TLS.
*/
void Client::initThread(const char *desc, AbstractMessagingPort *mp) {
invariant(currentClient.get() == 0);
string fullDesc;
if (mp != NULL) {
fullDesc = str::stream() << desc << mp->connectionId();
}
else {
fullDesc = desc;
}
setThreadName(fullDesc.c_str());
mongo::lastError.initThread();
// Create the client obj, attach to thread
Client* client = new Client(fullDesc, mp);
client->setAuthorizationSession(
new AuthorizationSession(
new AuthzSessionExternalStateMongod(getGlobalAuthorizationManager())));
currentClient.reset(client);
// This makes the client visible to maintenance threads
boost::lock_guard<boost::mutex> clientLock(clientsMutex);
clients.insert(client);
}
开发者ID:ambroff,项目名称:mongo,代码行数:30,代码来源:client.cpp
示例12: threadRun
void threadRun( MessagingPort * inPort) {
TicketHolderReleaser connTicketReleaser( &connTicketHolder );
setThreadName( "conn" );
assert( inPort );
inPort->setLogLevel(1);
scoped_ptr<MessagingPort> p( inPort );
p->postFork();
string otherSide;
Message m;
try {
LastError * le = new LastError();
lastError.reset( le ); // lastError now has ownership
otherSide = p->remoteString();
handler->connected( p.get() );
while ( ! inShutdown() ) {
m.reset();
p->clearCounters();
if ( ! p->recv(m) ) {
if( !cmdLine.quiet )
log() << "end connection " << otherSide << endl;
p->shutdown();
break;
}
handler->process( m , p.get() , le );
networkCounter.hit( p->getBytesIn() , p->getBytesOut() );
}
}
catch ( AssertionException& e ) {
log() << "AssertionException handling request, closing client connection: " << e << endl;
p->shutdown();
}
catch ( SocketException& e ) {
log() << "SocketException handling request, closing client connection: " << e << endl;
p->shutdown();
}
catch ( const ClockSkewException & ) {
log() << "ClockSkewException - shutting down" << endl;
exitCleanly( EXIT_CLOCK_SKEW );
}
catch ( std::exception &e ) {
error() << "Uncaught std::exception: " << e.what() << ", terminating" << endl;
dbexit( EXIT_UNCAUGHT );
}
catch ( ... ) {
error() << "Uncaught exception, terminating" << endl;
dbexit( EXIT_UNCAUGHT );
}
handler->disconnected( p.get() );
}
开发者ID:dgriffith,项目名称:mongo,代码行数:60,代码来源:message_server_port.cpp
示例13: setThreadName
void AsynchronousMetrics::run()
{
setThreadName("AsyncMetrics");
std::unique_lock<std::mutex> lock{wait_mutex};
/// Next minute + 30 seconds. To be distant with moment of transmission of metrics, see MetricsTransmitter.
const auto get_next_minute = []
{
return std::chrono::time_point_cast<std::chrono::minutes, std::chrono::system_clock>(
std::chrono::system_clock::now() + std::chrono::minutes(1)) + std::chrono::seconds(30);
};
while (true)
{
if (wait_cond.wait_until(lock, get_next_minute(), [this] { return quit; }))
break;
try
{
update();
}
catch (...)
{
tryLogCurrentException(__PRETTY_FUNCTION__);
}
}
}
开发者ID:yurial,项目名称:ClickHouse,代码行数:28,代码来源:AsynchronousMetrics.cpp
示例14: getPocoThread
void ofxMtJsonParser::threadedFunction(){
#if( OF_VERSION_MINOR <= 9 )
try {
getPocoThread().setName("ofxMtJsonParser");
getPocoThread().setOSPriority(Poco::Thread::getMinOSPriority());
} catch (Poco::SystemException exc) {
ofLogError("ofxMtJsonParser") << exc.what() << " " << exc.message() << " " << exc.displayText();
}
#else
setThreadName("ofxMtJsonParser");
#endif
switch (state) {
case CHECKING_JSON:
checkLocalJsonAndSplitWorkload();
ofSleepMillis(16);
break;
case MERGE_THREAD_RESULTS:
mergeThreadResults();
ofSleepMillis(16);
break;
default: break;
}
}
开发者ID:local-projects,项目名称:ofxMTJsonParser,代码行数:27,代码来源:ofxMtJsonParser.cpp
示例15: setThreadName
// a nice simple constructor
Joydrive::Joydrive(ArRobot *robot)
{
setThreadName("Joydrive");
// set the robot pointer
myRobot = robot;
// initialize the joystick
myJoyHandler.init();
// set up the joystick so we'll get the speeds out we want
myJoyHandler.setSpeeds(40, 700);
// see if we have a joystick, and let the users know
if (myJoyHandler.haveJoystick())
{
printf("Have a joystick\n\n");
}
// if we don't have a joystick, then print error message and exit
else
{
printf("Do not have a joystick, set up the joystick then rerun the program\n\n");
Aria::exit(1); // exit program with error code 1
}
// this is what creates are own thread, its from the ArASyncTask
create();
}
开发者ID:sendtooscar,项目名称:ariaClientDriver,代码行数:26,代码来源:joydriveThreaded.cpp
示例16: applyPriority
void BaseThread::doRun()
{
m_pPrivates->m_bIsRunning = true;
applyPriority();
setThreadName();
run();
}
开发者ID:Mailaender,项目名称:Desurium,代码行数:7,代码来源:BaseThread.cpp
示例17: setThreadName
void CClient::run()
{
setThreadName("CClient::run");
try
{
while(!terminate)
{
CPack *pack = serv->retreivePack(); //get the package from the server
if (terminate)
{
vstd::clear_pointer(pack);
break;
}
handlePack(pack);
}
}
//catch only asio exceptions
catch (const boost::system::system_error& e)
{
logNetwork->errorStream() << "Lost connection to server, ending listening thread!";
logNetwork->errorStream() << e.what();
if(!terminate) //rethrow (-> boom!) only if closing connection was unexpected
{
logNetwork->errorStream() << "Something wrong, lost connection while game is still ongoing...";
throw;
}
}
}
开发者ID:DavidZeni,项目名称:vcmi,代码行数:30,代码来源:Client.cpp
示例18: GenericSchedulerThread
TrackScheduler::TrackScheduler(const TrackerParamsProviderBasePtr& paramsProvider)
: GenericSchedulerThread()
, _imp( new TrackSchedulerPrivate(paramsProvider) )
{
QObject::connect( this, SIGNAL(renderCurrentFrameForViewer(ViewerInstancePtr)), this, SLOT(doRenderCurrentFrameForViewer(ViewerInstancePtr)) );
setThreadName("TrackScheduler");
}
开发者ID:kcotugno,项目名称:Natron,代码行数:8,代码来源:TrackScheduler.cpp
示例19: setThreadName
Client& Client::initThread(const char *desc, AbstractMessagingPort *mp) {
setThreadName(desc);
assert( currentClient.get() == 0 );
Client *c = new Client(desc, mp);
currentClient.reset(c);
mongo::lastError.initThread();
return *c;
}
开发者ID:MSchireson,项目名称:mongo,代码行数:8,代码来源:s_only.cpp
示例20: ArASyncTask
AREXPORT ArSyncLoop::ArSyncLoop() :
ArASyncTask(),
myStopRunIfNotConnected(false),
myRobot(0)
{
setThreadName("ArSyncLoop");
myInRun = false;
}
开发者ID:sanyaade-research-hub,项目名称:aria,代码行数:8,代码来源:ArSyncLoop.cpp
注:本文中的setThreadName函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论