【发布时间】:2017-01-26 19:24:04
【问题描述】:
在 C 中使用 pthreads,有没有办法访问特定线程的程序计数器/指令指针?
例子:
void *thread_main(void *arg) {
long thread = (long)arg;
lock (thread);
***print (thread.pc);***
critical_section (thread);
***print (thread.pc);***
unlock (thread);
return NULL;
}
【问题讨论】:
-
您是在寻找跨平台解决方案,还是只需要它在特定平台(例如 Windows 等)上工作。
-
C 没有“程序计数器”的概念。您可以使用
__FILE__、__func__和__LINE__宏来识别当前正在执行的代码部分。 -
@i_am_jorf 我有一台 MacOS 和一台 Debian 机器。所以两者都可以接受:)
-
写一个从栈中获取返回地址的函数能解决你的问题吗?
-
您可以使用these 解决方案访问寄存器,但据我所知,您需要在您关心的线程上执行此操作。
标签: c multithreading pthreads program-counter