本文链接

https://www.cnblogs.com/wanger-sjtu/p/16817532.html

最近在解决tvm绑核问题时,发现android下绑核只有sched_setaffinity函数,这导致无法使用标准库中的td::thread::native_handle_type thread 进行绑核操作。虽然在ndk 21以上的版本提供了pthread_gettid_np函数获取线程相应的pid,但在较低版本中,还是没办法直接使用。

看下ndk 中 std 标准库上thread 的实现。

class _LIBCPP_TYPE_VIS thread
{
    __libcpp_thread_t __t_;
   ... public:
    typedef __thread_id id;
    typedef __libcpp_thread_t native_handle_type;
...
}; typedef pthread_t __libcpp_thread_t;
typedef long pthread_t;

上面可以看出,在ndk的实现中native_handle_type 等价于pthread_t, 再根据pthread_gettid_np的实现,可以发现 ,pthread_t 其实就是pthread_internal_t的地址。在pthread_internal_t中保存了线程的tid


pid_t pthread_gettid_np(pthread_t t) {
return __pthread_internal_gettid(t, "pthread_gettid_np");
} pid_t __pthread_internal_gettid(pthread_t thread_id, const char* caller) {
pthread_internal_t* thread = __pthread_internal_find(thread_id, caller);
return thread ? thread->tid : -1; }
typedef struct pthread_internal_t

{

struct pthread_internal_t* next;

struct pthread_internal_t* prev;

pthread_attr_t attr;

pid_t tid;

bool allocated_on_heap;

pthread_cond_t join_cond;

int join_count;

void* return_value;

int internal_flags;

__pthread_cleanup_t* cleanup_stack;

void** tls; /* thread-local storage area */

/*

* The dynamic linker implements dlerror(3), which makes it hard for us to implement this

* per-thread buffer by simply using malloc(3) and free(3).

*/

#define __BIONIC_DLERROR_BUFFER_SIZE 512

char dlerror_buffer[__BIONIC_DLERROR_BUFFER_SIZE];

} pthread_internal_t;

ndk std_thread 获取pid的更多相关文章

  1. 获取Pid

    Java程序中获取当前进程的进程ID 标签: javainterfacesystemcompilationjvmjni 2011-12-29 16:31 15182人阅读 评论(2) 收藏 举报  分 ...

  2. 根据PID获取进程名&根据进程名获取PID

    Liunx中 通过进程名查找进程PID可以通过 pidof [进程名] 来查找.反过来 ,相同通过PID查找进程名则没有相关命令.在linux根目录中,有一个/proc的VFS(虚拟文件系统),系统当 ...

  3. python 通过js控制滚动条拉取全文 通过psutil获取pid窗口句柄,通过win32gui使程序窗口前置 通过autopy实现右键菜单和另存为操作

    1.参考 利用 Python + Selenium 自动化快速截图 利用 Python + Selenium 实现对页面的指定元素截图(可截长图元素) 使用python获取系统所有进程PID以及进程名 ...

  4. linux下根据进程名字获取PID,类似pidof(转)

    linux有一个命令行工具叫做pidof,可以根据用户输入的进程名字查找到进程号,但有时候我们需要在程序里实现,不想调用system,在查阅了很多版本的pidof源代码后,没有发现一个自己感觉比较好的 ...

  5. linux根据进程名获取PID

    经常需要Kill多个进程,这些进程包含共同的关键字,可以用一条命令Kill掉它们. ps aux | grep "common" |grep -v grep| cut -c 9-1 ...

  6. Bash Shell 获取进程 PID

    转载地址:http://weyo.me/pages/techs/linux-get-pid/ 导读 Linux 的交互式 Shell 与 Shell 脚本存在一定的差异,主要是由于后者存在一个独立的运 ...

  7. linux shell 获取进程pid

    1.通过可执行程序的程序名称 a.运行程序 b.获取进程id号 c.pidof相关知识:http://www.cnblogs.com/yunsicai/p/3675938.html 2.有些程序需要在 ...

  8. CMD魔法堂:获取进程路径和PID值的方法集

    一.前言    在开发发布更更新工具——更新Weblogic应用模块时,了解到更新Weblogic应用需要先关闭Weblogic应用窗口然后是清缓存.更新应用文件,最后再重启Weblogic应用窗口. ...

  9. linux命令(26):Bash Shell 获取进程 PID

    转载地址:http://weyo.me/pages/techs/linux-get-pid/ 根据pid,kill该进程:http://www.cnblogs.com/lovychen/p/54113 ...

  10. 014-交互式Shell和shell脚本获取进程 pid

    Linux 的交互式 Shell 与 Shell 脚本存在一定的差异,主要是由于后者存在一个独立的运行进程 1.交互式 Bash Shell 获取进程 pid 在已知进程名(name)的前提下,交互式 ...

随机推荐

  1. vue之数组与对象的检测与更新

    目录 说明 语法 示例 说明 MVVM会自动检测变量的变化,当变量改变,页面也会对应的变化,但是有一点需要注意,如果有一个对象增加值的时候,不能直接修改,需要使用Vue.set()方法 语法 Vue. ...

  2. Mybatis中批量插入和一些问题的解决

    批量插入有三个问题,第一是执行效率,第二数据冲突,第三数据重跑更新操作. 一般对于这样的问题有以下操作方法. 第一是执行效率:mybatis支持两种高效插入. 1.mybtis的foreach标签,f ...

  3. pandas之字符串操作

    Pandas 提供了一系列的字符串函数,因此能够很方便地对字符串进行处理.在本节,我们使用 Series 对象对常用的字符串函数进行讲解.常用的字符串处理函数如下表所示: 函数名称 函数功能和描述 l ...

  4. python内置模块之ctype

    ctypes --- Python 的外部函数库¶ ctypes 是 Python 的外部函数库.它提供了与 C 兼容的数据类型,并允许调用 DLL 或共享库中的函数.可使用该模块以纯 Python ...

  5. Mybatis 框架下 SQL 注入攻击的方式

    前言 SQL注入漏洞作为WEB安全的最常见的漏洞之一,在java中随着预编译与各种ORM框架的使用,注入问题也越来越少. 新手代码审计者往往对Java Web应用的多个框架组合而心生畏惧,不知如何下手 ...

  6. JUC(四)多线程锁

    目录 多线程锁 Synchronized锁的八种情况 公平锁和非公平锁 可重入锁 synchronized Lock 死锁 检查死锁 多线程锁 Synchronized锁的八种情况 以一个手机类为例, ...

  7. jmap执行失败了,怎么获取heapdump?

    原创:扣钉日记(微信公众号ID:codelogs),欢迎分享,非公众号转载保留此声明. 在之前的OOM问题复盘中,我们添加了jmap脚本来自动dump内存现场,方便排查OOM问题. 但当我反复模拟OO ...

  8. 3385. 【NOIP2013模拟】黑魔法师之门

    3385. [NOIP2013模拟]黑魔法师之门 题目大意: 做法: 代码: 题目大意: 给你一个无向无权图,每次询问加入一条边问你图中每个点的度数大于零且都是偶数的子图的个数对1000000009取 ...

  9. Prisim Sample 7 Modules App.Config

    在项目中添加模块化文件.模块文件怎样在主项目中注册.本例 说明方式一,使用了App.config文件. 其中: <?xml version="1.0" encoding=&q ...

  10. 【Redis】Redis 编译安装配置优化,多实例配置

    一.Redis 配置详解 # Redis configuration file example. # # Note that in order to read the configuration fi ...