本文整理汇总了C++中pthread_self函数的典型用法代码示例。如果您正苦于以下问题:C++ pthread_self函数的具体用法?C++ pthread_self怎么用?C++ pthread_self使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pthread_self函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int
main()
{
int failed = 0;
int i;
pthread_t t[NUMTHREADS + 1];
assert((t[0] = pthread_self()).p != NULL);
for (i = 1; i <= NUMTHREADS; i++)
{
threadbag[i].started = 0;
threadbag[i].threadnum = i;
assert(pthread_create(&t[i], NULL, mythread, (void *) &threadbag[i]) == 0);
}
/*
* Code to control or munipulate child threads should probably go here.
*/
Sleep(1000);
/*
* Standard check that all threads started.
*/
for (i = 1; i <= NUMTHREADS; i++)
{
if (!threadbag[i].started)
{
failed |= !threadbag[i].started;
fprintf(stderr, "Thread %d: started %d\n", i, threadbag[i].started);
}
}
assert(!failed);
/*
* Check any results here. Set "failed" and only print output on failure.
*/
failed = 0;
for (i = 1; i <= NUMTHREADS; i++)
{
int fail = 0;
int result = 0;
assert(pthread_join(t[i], (void **) &result) == 0);
fail = (result != 0);
if (fail)
{
fprintf(stderr, "Thread %d: started %d: result: %d\n",
i,
threadbag[i].started,
result);
}
failed = (failed || fail);
}
assert(!failed);
assert(pop_count == NUMTHREADS);
/*
* Success.
*/
return 0;
}
示例2: thr_demarshal
// Set of threads which talk to client over the connection for doing the needful
// processing. Note that once fd is assigned to a thread all the work on that fd
// is done by that thread. Fair fd usage is expected of the client. First thread
// is special - also does accept [listens for new connections]. It is the only
// thread which does it.
void *
thr_demarshal(void *arg)
{
cf_socket_cfg *s, *ls, *xs;
// Create my epoll fd, register in the global list.
struct epoll_event ev;
int nevents, i, n, epoll_fd;
cf_clock last_fd_print = 0;
#if defined(USE_SYSTEMTAP)
uint64_t nodeid = g_config.self_node;
#endif
// Early stage aborts; these will cause faults in process scope.
cf_assert(arg, AS_DEMARSHAL, CF_CRITICAL, "invalid argument");
s = &g_config.socket;
ls = &g_config.localhost_socket;
xs = &g_config.xdr_socket;
#ifdef USE_JEM
int orig_arena;
if (0 > (orig_arena = jem_get_arena())) {
cf_crash(AS_DEMARSHAL, "Failed to get original arena for thr_demarshal()!");
} else {
cf_info(AS_DEMARSHAL, "Saved original JEMalloc arena #%d for thr_demarshal()", orig_arena);
}
#endif
// Figure out my thread index.
pthread_t self = pthread_self();
int thr_id;
for (thr_id = 0; thr_id < MAX_DEMARSHAL_THREADS; thr_id++) {
if (0 != pthread_equal(g_demarshal_args->dm_th[thr_id], self))
break;
}
if (thr_id == MAX_DEMARSHAL_THREADS) {
cf_debug(AS_FABRIC, "Demarshal thread could not figure own ID, bogus, exit, fu!");
return(0);
}
// First thread accepts new connection at interface socket.
if (thr_id == 0) {
demarshal_file_handle_init();
epoll_fd = epoll_create(EPOLL_SZ);
if (epoll_fd == -1) {
cf_crash(AS_DEMARSHAL, "epoll_create(): %s", cf_strerror(errno));
}
memset(&ev, 0, sizeof (ev));
ev.events = EPOLLIN | EPOLLERR | EPOLLHUP;
ev.data.fd = s->sock;
if (0 > epoll_ctl(epoll_fd, EPOLL_CTL_ADD, s->sock, &ev)) {
cf_crash(AS_DEMARSHAL, "epoll_ctl(): %s", cf_strerror(errno));
}
cf_info(AS_DEMARSHAL, "Service started: socket %s:%d", s->addr, s->port);
if (ls->sock) {
ev.events = EPOLLIN | EPOLLERR | EPOLLHUP;
ev.data.fd = ls->sock;
if (0 > epoll_ctl(epoll_fd, EPOLL_CTL_ADD, ls->sock, &ev)) {
cf_crash(AS_DEMARSHAL, "epoll_ctl(): %s", cf_strerror(errno));
}
cf_info(AS_DEMARSHAL, "Service also listening on localhost socket %s:%d", ls->addr, ls->port);
}
if (xs->sock) {
ev.events = EPOLLIN | EPOLLERR | EPOLLHUP;
ev.data.fd = xs->sock;
if (0 > epoll_ctl(epoll_fd, EPOLL_CTL_ADD, xs->sock, &ev)) {
cf_crash(AS_DEMARSHAL, "epoll_ctl(): %s", cf_strerror(errno));
}
cf_info(AS_DEMARSHAL, "Service also listening on XDR info socket %s:%d", xs->addr, xs->port);
}
}
else {
epoll_fd = epoll_create(EPOLL_SZ);
if (epoll_fd == -1) {
cf_crash(AS_DEMARSHAL, "epoll_create(): %s", cf_strerror(errno));
}
}
g_demarshal_args->epoll_fd[thr_id] = epoll_fd;
cf_detail(AS_DEMARSHAL, "demarshal thread started: id %d", thr_id);
int id_cntr = 0;
//.........这里部分代码省略.........
示例3: CRYPTO_THREAD_get_current_id
CRYPTO_THREAD_ID CRYPTO_THREAD_get_current_id(void)
{
return pthread_self();
}
示例4: pthread_self
////////////////////////////////////////////////////////////
// static
XThreadID_pthread_t XLockPthreadMutex::sGetThreadID( void ) {
pthread_t pthid = pthread_self();
XThreadID_pthread_t idThread( pthid );
// DWORD idThread = (DWORD) pthid.p;
return idThread;
}
示例5: main
//Execute par le thread principal (controleur)
int main (int argc, char **argv)
{
if (argc != 6)
return EXIT_FAILIURE;
signal(SIGALRM, sigHandler);
std::string pathGrilleVide = argv[1];
std::string pathGrilleSolution = argv[2];
std::string pathArrivee = argv[3];
int tempsMax = atoi(argv[4]);
pathResultat = argv[5];
int grille[9][9];
int solution[9][9];
mainThread = pthread_self();
loadGrid(pathGrilleVide, grille);
// printGrid(grille);
loadGrid(pathGrilleSolution, solution);
// printGrid(solution);
for (int i = 0; i < 5; i++)
{
joueurs[i] == 0;
}
//creaation des thread joueur par defaut
joueurs[0] = new Joueur();
joueurs[1] = new Joueur();
joueurs[2] = new Joueur();
joueurs[0]->thread = new pthread_t();
joueurs[1]->thread = new pthread_t();
joueurs[2]->thread = new pthread_t();
int un=1;
int deux=2;
int trois=3;
pthread_create(joueurs[0]->thread, NULL, jouer, &un);
pthread_create(joueurs[1]->thread, NULL, jouer, &deux);
pthread_create(joueurs[2]->thread, NULL, jouer, &trois);
joueurs[0]->tid = 1;
joueurs[1]->tid = 2;
joueurs[2]->tid = 3;
joueurs[0]->etat = "Inconnu";
joueurs[1]->etat = "Inconnu";
joueurs[2]->etat = "Inconnu";
listeJoueurs.insert(std::pair<int, Joueur*>(joueurs[0]->tid, joueurs[0]));
listeJoueurs.insert(std::pair<int, Joueur*>(joueurs[1]->tid, joueurs[1]));
listeJoueurs.insert(std::pair<int, Joueur*>(joueurs[2]->tid, joueurs[2]));
// Creation des deux autres thread
pthread_t accueil_t;
pthread_t alarm_t;
pthread_create(&accueil_t, NULL, accueil, (void*)pathArrivee.c_str());
pthread_create(&alarm_t, NULL, minuterie, (void*)&tempsMax);
sem_init(&file1_sem, 0, 0);
int* empty = findEmpty(grille);
int col = 0, ln = 0;
do
{
//============================================================
// BOUCLE POUR TROUVER LES ZERO ET LES ENVOYER DANS LA FILE 1
if (empty == 0)
break;
if (pthread_mutex_trylock(&file1_lock) == 0)
{
// std::cout<<"je prend le mutex pour le broadcast"<<std::endl;
if (file1.size() < 4)
{
MessageCJ* msg = new MessageCJ();
msg->colonne = empty[0];
msg->ligne = empty[1];
bool duplicate = false;
std::queue<MessageCJ*> temp;
while(!file1.empty())
{
temp.push(new MessageCJ((*file1.front())));
file1.pop();
}
while(!temp.empty())
{
MessageCJ* tmpMsg = new MessageCJ((*temp.front()));
//.........这里部分代码省略.........
示例6: findLockInfo
/*
** Given a file descriptor, locate lockInfo and openCnt structures that
** describes that file descriptor. Create a new ones if necessary. The
** return values might be unset if an error occurs.
**
** Return the number of errors.
*/
static int findLockInfo(
int fd, /* The file descriptor used in the key */
struct lockInfo **ppLock, /* Return the lockInfo structure here */
struct openCnt **ppOpen /* Return the openCnt structure here */
){
int rc;
struct lockKey key1;
struct openKey key2;
struct stat statbuf;
struct lockInfo *pLock;
struct openCnt *pOpen;
rc = fstat(fd, &statbuf);
if( rc!=0 ) return 1;
memset(&key1, 0, sizeof(key1));
key1.dev = statbuf.st_dev;
key1.ino = statbuf.st_ino;
#ifdef SQLITE_UNIX_THREADS
if( threadsOverrideEachOthersLocks<0 ){
testThreadLockingBehavior(fd);
}
key1.tid = threadsOverrideEachOthersLocks ? 0 : pthread_self();
#endif
memset(&key2, 0, sizeof(key2));
key2.dev = statbuf.st_dev;
key2.ino = statbuf.st_ino;
pLock = (struct lockInfo*)sqlite3HashFind(&lockHash, &key1, sizeof(key1));
if( pLock==0 ){
struct lockInfo *pOld;
pLock = (lockInfo*)sqliteMallocRaw( sizeof(*pLock) );
if( pLock==0 ) return 1;
pLock->key = key1;
pLock->nRef = 1;
pLock->cnt = 0;
pLock->locktype = 0;
pOld = (lockInfo*)sqlite3HashInsert(&lockHash, &pLock->key, sizeof(key1), pLock);
if( pOld!=0 ){
assert( pOld==pLock );
sqliteFree(pLock);
return 1;
}
}else{
pLock->nRef++;
}
*ppLock = pLock;
pOpen = (struct openCnt*)sqlite3HashFind(&openHash, &key2, sizeof(key2));
if( pOpen==0 ){
struct openCnt *pOld;
pOpen = (openCnt*)sqliteMallocRaw( sizeof(*pOpen) );
if( pOpen==0 ){
releaseLockInfo(pLock);
return 1;
}
pOpen->key = key2;
pOpen->nRef = 1;
pOpen->nLock = 0;
pOpen->nPending = 0;
pOpen->aPending = 0;
pOld = (openCnt*)sqlite3HashInsert(&openHash, &pOpen->key, sizeof(key2), pOpen);
if( pOld!=0 ){
assert( pOld==pOpen );
sqliteFree(pOpen);
releaseLockInfo(pLock);
return 1;
}
}else{
pOpen->nRef++;
}
*ppOpen = pOpen;
return 0;
}
示例7: ldap_pvt_thread_self
ldap_pvt_thread_t ldap_pvt_thread_self( void )
{
return pthread_self();
}
示例8: main
int
main()
{
int failed = 0;
int i;
int first, last;
pthread_t t[NUMTHREADS + 1];
#if (defined(__MINGW64__) || defined(__MINGW32__)) && __MSVCRT_VERSION__ >= 0x0601
struct __timeb64 currSysTime;
#else
struct _timeb currSysTime;
#endif
const DWORD NANOSEC_PER_MILLISEC = 1000000;
assert((t[0] = pthread_self()).p != NULL);
assert(cvthing.notbusy == PTHREAD_COND_INITIALIZER);
assert(cvthing.lock == PTHREAD_MUTEX_INITIALIZER);
PTW32_FTIME(&currSysTime);
abstime.tv_sec = (long)currSysTime.time;
abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm;
abstime.tv_sec += 10;
assert((t[0] = pthread_self()).p != NULL);
awoken = 0;
for (first = 1, last = NUMTHREADS / 2;
first < NUMTHREADS;
first = last + 1, last = NUMTHREADS)
{
assert(pthread_mutex_lock(&start_flag) == 0);
for (i = first; i <= last; i++)
{
threadbag[i].started = 0;
threadbag[i].threadnum = i;
assert(pthread_create(&t[i], NULL, mythread, (void *) &threadbag[i]) == 0);
}
/*
* Code to control or munipulate child threads should probably go here.
*/
cvthing.shared = 0;
assert(pthread_mutex_unlock(&start_flag) == 0);
/*
* Give threads time to start.
*/
Sleep(100);
assert(pthread_mutex_lock(&cvthing.lock) == 0);
cvthing.shared++;
assert(pthread_mutex_unlock(&cvthing.lock) == 0);
assert(pthread_cond_broadcast(&cvthing.notbusy) == 0);
/*
* Give threads time to complete.
*/
for (i = first; i <= last; i++)
{
assert(pthread_join(t[i], NULL) == 0);
}
assert(awoken == (i - 1));
}
/*
* Standard check that all threads started.
*/
for (i = 1; i <= NUMTHREADS; i++)
{
failed = !threadbag[i].started;
if (failed)
{
fprintf(stderr, "Thread %d: started %d\n", i, threadbag[i].started);
}
}
/*
* Cleanup the CV.
*/
assert(pthread_mutex_destroy(&cvthing.lock) == 0);
assert(cvthing.lock == NULL);
assert(pthread_cond_destroy(&cvthing.notbusy) == 0);
assert(cvthing.notbusy == NULL);
//.........这里部分代码省略.........
示例9: Pthread_self
pthread_t Pthread_self(void) {
return pthread_self();
}
示例10: osThreadId
OSThreadId
osThreadId()
{
return pthread_self();
}
示例11: bs_errors
static void bs_errors (const char * msg) {
// we normally do not care to print all messages from blobstore as many are errors that we can handle
logprintfl (EUCADEBUG2, "{%u} blobstore: %s", (unsigned int)pthread_self(), msg);
}
示例12: pthread_self
void *DemodulatorPreThread::threadMain() {
#else
void DemodulatorPreThread::threadMain() {
#endif
#ifdef __APPLE__
pthread_t tID = pthread_self(); // ID of this thread
int priority = sched_get_priority_max( SCHED_FIFO) - 1;
sched_param prio = {priority}; // scheduling priority of thread
pthread_setschedparam(tID, SCHED_FIFO, &prio);
#endif
if (!initialized) {
initialize();
}
std::cout << "Demodulator preprocessor thread started.." << std::endl;
std::deque<DemodulatorThreadPostIQData *> buffers;
std::deque<DemodulatorThreadPostIQData *>::iterator buffers_i;
std::vector<liquid_float_complex> in_buf_data;
std::vector<liquid_float_complex> out_buf_data;
// liquid_float_complex carrySample; // Keep the stream count even to simplify some demod operations
// bool carrySampleFlag = false;
terminated = false;
while (!terminated) {
DemodulatorThreadIQData *inp;
iqInputQueue->pop(inp);
bool bandwidthChanged = false;
bool rateChanged = false;
DemodulatorThreadParameters tempParams = params;
if (!commandQueue->empty()) {
while (!commandQueue->empty()) {
DemodulatorThreadCommand command;
commandQueue->pop(command);
switch (command.cmd) {
case DemodulatorThreadCommand::DEMOD_THREAD_CMD_SET_BANDWIDTH:
if (command.llong_value < 1500) {
command.llong_value = 1500;
}
if (command.llong_value > params.sampleRate) {
tempParams.bandwidth = params.sampleRate;
} else {
tempParams.bandwidth = command.llong_value;
}
bandwidthChanged = true;
break;
case DemodulatorThreadCommand::DEMOD_THREAD_CMD_SET_FREQUENCY:
params.frequency = tempParams.frequency = command.llong_value;
break;
case DemodulatorThreadCommand::DEMOD_THREAD_CMD_SET_AUDIO_RATE:
tempParams.audioSampleRate = (int)command.llong_value;
rateChanged = true;
break;
default:
break;
}
}
}
if (inp->sampleRate != tempParams.sampleRate && inp->sampleRate) {
tempParams.sampleRate = inp->sampleRate;
rateChanged = true;
}
if (bandwidthChanged || rateChanged) {
DemodulatorWorkerThreadCommand command(DemodulatorWorkerThreadCommand::DEMOD_WORKER_THREAD_CMD_BUILD_FILTERS);
command.sampleRate = tempParams.sampleRate;
command.audioSampleRate = tempParams.audioSampleRate;
command.bandwidth = tempParams.bandwidth;
command.frequency = tempParams.frequency;
workerQueue->push(command);
}
if (!initialized) {
continue;
}
// Requested frequency is not center, shift it into the center!
if ((params.frequency - inp->frequency) != shiftFrequency || rateChanged) {
shiftFrequency = params.frequency - inp->frequency;
if (abs(shiftFrequency) <= (int) ((double) (wxGetApp().getSampleRate() / 2) * 1.5)) {
nco_crcf_set_frequency(freqShifter, (2.0 * M_PI) * (((double) abs(shiftFrequency)) / ((double) wxGetApp().getSampleRate())));
}
}
if (abs(shiftFrequency) > (int) ((double) (wxGetApp().getSampleRate() / 2) * 1.5)) {
continue;
}
// std::lock_guard < std::mutex > lock(inp->m_mutex);
std::vector<liquid_float_complex> *data = &inp->data;
if (data->size() && (inp->sampleRate == params.sampleRate)) {
int bufSize = data->size();
//.........这里部分代码省略.........
示例13: return
unsigned long SSLSupport::getThreadID(void)
{
return ((unsigned long) pthread_self());
}
示例14: fvl_srio_recver
static void fvl_srio_recver(void *arg)
{
fvl_tcp_socket_t tcp;
fvl_thread_arg_t *priv=arg;
fvl_srio_portpool_t *ppool;
fvl_srio_ctrlblk_t *pscb;
in_addr_t tcp_ip;
int tcp_port;
int rvl;
volatile fvl_srio_ctl_info_t *pcnt;
volatile fvl_srio_ctl_info_t *pclt;
fvl_srio_ctl_info_t packet_info;
fvl_srio_ctl_info_t test_info;
uint8_t *buf_virt;
uint32_t port;
uint32_t bfnum;
uint64_t *head_virt;
uint64_t head_phys;
uint64_t head_dest;
uint8_t ctl_count=1;
uint16_t send_size = sizeof(fvl_srio_ctl_info_t);
uint8_t i;
struct timeval tm_start,tm_end;
cpu_set_t cpuset;
CPU_ZERO(&cpuset);
CPU_SET(priv->cpu,&cpuset);
rvl = pthread_setaffinity_np(pthread_self(),sizeof(cpu_set_t),&cpuset);
if(rvl) {
printf("(%d)fail:pthread_setaffinity_np()\n",priv->cpu);
return;
}
tcp_ip = inet_addr("192.168.10.20");
tcp_port = 5000;
/* rvl = fvl_tcp_init(&tcp, tcp_ip, tcp_port);
if(rvl < 0) {
FVL_LOG("fvl_tcp_init failed, return %d\n", rvl);
return;
}*/
port = priv->port;
if(port >= FVL_SRIO_PORTNUM) {
FVL_LOG("Invalid port num: %u\n", port);
return;
}
bfnum = priv->bfnum;
ppool = &priv->psrio->portpool[port];
pscb = fvl_srio_getcb(port,bfnum);
if(pscb == NULL) {
FVL_LOG("Srio getcb failed\n");
return;
}
head_virt = (uint64_t*)ppool->pwrite_ctl_data[bfnum];
head_phys = ppool->write_ctl_data[bfnum];
head_dest = ppool->port_info.range_start+FVL_SRIO_DMA_WINSIZE+bfnum*FVL_SRIO_CTL_BUFSIZE;//important
pcnt = (fvl_srio_ctl_info_t *)ppool->pwrite_ctl_result[bfnum];
buf_virt = ppool->pwrite_result[bfnum];
pclt = pcnt;
bzero(&test_info,send_size);
test_info.FLA=0;
test_info.SET=0;
test_info.BIS=0;
#ifndef OLD_VERSION
test_info.RST=1;
test_info.CEN=0;
#endif
test_info.PK_ID=0;
test_info.SUB_BUF=0;
test_info.FCNT=0;
test_info.CH_ID=bfnum;
test_info.BUF_ADDR = 0;
test_info.BUF_SIZE = 1;
test_info.INFO_ADDR = 1;
memcpy(head_virt,&test_info,send_size);
fvl_srio_send(pscb, head_phys, head_dest, send_size);
usleep(5000);
bzero(&packet_info,send_size);
packet_info.FLA=0;
packet_info.SET=1;
packet_info.BIS=0;
#ifndef OLD_VERSION
packet_info.RST=0;
packet_info.CEN=0;
#endif
packet_info.PK_ID=1;
packet_info.SUB_BUF=0;
packet_info.FCNT = 0;
packet_info.CH_ID = bfnum;
packet_info.BUF_ADDR = FVL_SRIO_SYS_ADDR+bfnum*FVL_SRIO_DMA_BUFSIZE;
packet_info.BUF_SIZE = FVL_SRIO_DMA_BUFSIZE;
packet_info.INFO_ADDR = FVL_SRIO_CTL_ADDR +bfnum*FVL_SRIO_CTL_BUFSIZE;
memcpy(head_virt,&packet_info,send_size);
fvl_srio_send(pscb, head_phys, head_dest, send_size);
bzero(&test_info,send_size);
test_info.FLA=0;
test_info.SET=0;
test_info.BIS=0;
#ifndef OLD_VERSION
test_info.RST=0;
test_info.CEN=1;
#endif
//.........这里部分代码省略.........
示例15: TRI_IsSelfThread
bool TRI_IsSelfThread (TRI_thread_t* thread) {
return pthread_self() == *thread;
}