线程相关函数(2)-pthread_self()获取调用线程ID
获取调用线程tid
#include <pthread.h>
pthread_t pthread_self(void);
示例:
#include <pthread.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h> void *printids(void *arg)
{
const char *str = (const char *)arg; pid_t pid;
pthread_t tid; pid = getpid();
tid = pthread_self();
printf("%s pid %u tid %u (0x%x)\n", str, (unsigned int)pid, (unsigned int)tid, (unsigned int)tid); } int main()
{ pthread_t tid;
int err; err = pthread_create(&tid, NULL, printids, "new thread: ");
if (err != ) {
fprintf(stderr, "can't create thread: %s\n", strerror(err));
exit();
}
printids("main thread: ");
sleep();
return ; }
运行结果:
main thread: pid 4959 tid 9791296 (0x956740)
new thread: pid 4959 tid 1480448 (0x169700)
线程相关函数(2)-pthread_self()获取调用线程ID的更多相关文章
- 线程相关函数(3)-pthread_detach()将某个线程设成分离态
#include <pthread.h>int pthread_detach(pthread_t tid); pthread_t tid: 分离线程的tid返回值:成功返回0,失败返回错误 ...
- linux c 线程相关函数
线程相关函数(1)-pthread_create(), pthread_join(), pthread_exit(), pthread_cancel() 创建取消线程 一. pthread_creat ...
- linux线程相关函数接口
以下内容转自网络 索引:1.创建线程pthread_create2.等待线程结束pthread_join3.分离线程pthread_detach4.创建线程键pthread_key_create5.删 ...
- 调用线程无法访问此对象,因为另一个线程拥有该对象 [c# wpf定时器程序报的错误]
WPF:Dispatcher.Invoke 方法,只有在其上创建 Dispatcher 的线程才可以直接访问DispatcherObject.若要从不同于在其上创建 DispatcherObject ...
- WPF [调用线程无法访问此对象,因为另一个线程拥有该对象。] 解决方案以及如何实现字体颜色的渐变
本文说明WPF [调用线程无法访问此对象,因为另一个线程拥有该对象.] 解决方案以及如何实现字体颜色的渐变 先来看看C#中Timer的简单说明,你想必猜到实现需要用到Timer的相关知识了吧. C# ...
- 【.NET线程--进阶(一)】--线程方法详解
上篇博客从线程的基本概况开始着重讨论了线程,进程,程序之间的区别,然后讨论了线程操作的几个类,并通过实例来说明了线程的创建方法.本篇博客将会带大家更深入的了解线程,介绍线程的基本方法,并通过一个Dem ...
- 深入Java线程管理(一):线程的实现方式
Java的线程实现方式一共有三种,继承Thread.实现Runable接口,实现Callable接口.不过实现Runnable接口与实现Callable接口的方式基本相同,只是Callable接口里定 ...
- 利用进程ID获取主线程ID
利用进程ID获取主线程ID,仅适用于单线程.多线程应区分哪个是主线程,区分方法待验证 (1)好像可以用StartTime最早的,不过通过线程执行时间不一定可靠,要是在最开始就CreateThread了 ...
- std::thread中获取当前线程的系统id
std::thread不提供获取当前线程的系统id的方法,仅可以获取当前的线程id,但是我们可以通过建立索引表的方式来实现 std::mutex m; std::map<std::thread: ...
随机推荐
- jenkins中“Poll SCM”和“Build periodically”的区别
Poll SCM:定时检查源码变更(根据SCM软件的版本号),如果有更新就checkout最新code下来,然后执行构建动作.我的配置如下: */5 * * * * (每5分钟检查一次源码变化) B ...
- HTML:几个常见的列表标签
介绍: 在网页中列表是很常见的标签,主要分为有序标签.无序标签.列表嵌套.定义标签 有序标签:<ol><li></li><ol> 无序标签:<ul ...
- go语言基础之函数只有一个返回值
1.函数只有一个返回值 示例1: package main //必须有一个main包 import "fmt" func myfunc01() int { return 666 } ...
- hdu 1024 dp滚动数组
#include <cstdio> #include <iostream> #include <algorithm> #include <queue> ...
- 词向量( Distributed Representation)工作原理是什么
原文:http://www.zhihu.com/question/21714667 4 个回答 83赞同反对,不会显示你的姓名 皮果提 刘鑫.莫教授要养猫.Starling Niohuru 等人赞同 ...
- jQuery框架开发一个最简单的幻灯效果
在线演示 在这个课程中,我们将介绍如何使用jQuery来开发一个最简单的图片幻灯效果. 立刻观看互动课程:jQuery框架开发一个最简单的幻灯效果 阅读原文:jQuery框架开发一个最简单的幻灯效果
- 关于listview,scrollview显示模糊边缘的设置
朋友们有时可能在开发中遇到这样的莫名其妙的问题,listview或scrollview滑动时上边和下边会出现两条模糊的边缘,有时会影响到我们app的视觉效果,我们怎么去掉这两条模糊的边缘呢?很简单,一 ...
- 很全的Python 面试题 github
https://github.com/taizilongxu/interview_python
- 流编辑器sed
sed与grep一样,都起源于老式的ed编辑器,因其是一个流编辑器(stream editor)而得名.与vi等编辑器不同,sed是一种非交互式编辑器(即用户不必参与编辑过程),它使用预先设定好的编辑 ...
- Python 对字符串切片
对字符串切片字符串 'xxx'和 Unicode字符串 u'xxx'也可以看成是一种list,每个元素就是一个字符.因此,字符串也可以用切片操作,只是操作结果仍是字符串:>>> 'A ...