- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个可以打印一些数据结构的代码。
void
print_wheel_timer(wheel_timer_t *wt){
<code to print data structure>
}
Then i sandwiched the code in-between lock and unlock mutex calls.
void
print_wheel_timer(wheel_timer_t *wt){
pthread_mutex_lock(&wt->global_lock);
<code to print data structure>
pthread_mutex_unlock(&wt->global_lock);
}
现在,出现了段错误。我已经禁用了代码中的所有线程,现在程序是单线程的,仍然是段错误。我使用的是 gcc,ubuntu 19.04。
gdb 显示 pthread_mutex_lock()
调用正在搞乱数据结构!这很奇怪!我将观察点放在由任意值写入的地址上,它显示对 pthread_mutex_lock() 的调用正在修改它。当我删除这些锁定/解锁调用时,没有看到段错误。
(gdb) watch *(glthread_t *)&(wt->slotlist[1].slots.right)
Hardware watchpoint 2: *(glthread_t *)&(wt->slotlist[1].slots.right)
(gdb) c
Continuing.
Printing Wheel Timer DS
Thread 1 "test.exe" hit Hardware watchpoint 2: *(glthread_t *)&(wt->slotlist[1].slots.right)
Old value = {left = 0x0, right = 0x0}
New value = {left = 0x1, right = 0x0} <<< corruption !!
0x00007ffff7fa3934 in __GI___pthread_mutex_lock (mutex=0x5555555771d8)
at ../nptl/pthread_mutex_lock.c:80
80 ../nptl/pthread_mutex_lock.c: No such file or directory.
(gdb) bt
#0 0x00007ffff7fa3934 in __GI___pthread_mutex_lock (mutex=0x5555555771d8)
at ../nptl/pthread_mutex_lock.c:80
#1 0x000055555555f3a2 in print_wheel_timer (wt=0x555555577180)
at WheelTimer/WheelTimer.c:276
Code :
========
void
print_wheel_timer(wheel_timer_t *wt){
int i = 0, j = 0;
glthread_t *curr;
glthread_t *slot_list_head = NULL;
wheel_timer_elem_t *wt_elem = NULL;
printf("Printing Wheel Timer DS\n");
pthread_mutex_lock(&wt->global_lock);
printf("wt->current_clock_tic = %d\n", wt->current_clock_tic);
printf("wt->clock_tic_interval = %d\n", wt->clock_tic_interval);
printf("wt->wheel_size = %d\n", wt->wheel_size);
printf("wt->current_cycle_no = %d\n", wt->current_cycle_no);
printf("wt->wheel_thread = %p\n", &wt->wheel_thread);
printf("WT uptime = %s\n", hrs_min_sec_format(WT_UPTIME(wt)));
printf("wt->no_of_wt_elem = %u\n", wt->no_of_wt_elem);
printf("printing slots : \n");
for(; i < wt->wheel_size; i++){
slot_list_head = WT_SLOTLIST_HEAD(wt, i);
ITERATE_GLTHREAD_BEGIN(slot_list_head, curr){ << segfaulting here for i = 1
wt_elem = glthread_to_wt_elem(curr);
如果某个神圣的灵魂想在他的机器上尝试一下。 请在这里下载代码: https://github.com/sachinites/tcpip_stack
After downloading :
switch to branch "Hellos"
git checkout Hellos
Compile :
make all
run
./test.exe
to reproduce , run the cmd :
debug show node H1 timer
现在它将以函数为核心:在WheelTimer/WheelTimer.c中实现的print_wheel_timer()
最佳答案
问题出在我的数据结构上,其中零长度数组是 C 结构的非最后一个成员,在读/写到此类数组时会损坏内存。可拉伸(stretch)数组应该是结构的最后一个成员。
typedef struct _wheel_timer_t {
int current_clock_tic;
int clock_tic_interval;
int wheel_size;
int current_cycle_no;
pthread_t wheel_thread;
slotlist_t slotlist[0]; << problem, make it last member
slotlist_t reschd_list;
unsigned int no_of_wt_elem;
pthread_mutex_t global_lock;
} wheel_timer_t;
关于c - pthread_mutex_lock() 处的段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58596496/
这个问题已经有答案了: What is the difference between a variable, object, and reference? [duplicate] (5 个回答) 已关
我正在使用以下代码来学习java套接字编程。它的作用是,client.java 程序从用户那里获取一个号码并将其发送到 sever.java。然后服务器将其乘以2并发回给客户端。在我的客户端程序中,它
我编写了一个自己开发的串行端口类,为了简单起见,我使用了阻塞/同步/非重叠。我浏览了所有 MSDN 文档,这对我来说很困难。 我在从端口打开、传输或接收字节方面没有任何问题。所有操作都是同步并且没有线
//Not finished -- disregard function evaluate() { var cdate = new Date(); var cday = cdate.getDa
我已经尝试过了,但它有效 例如: x= 523.897 y= x[0:"."] print y 我只想打印 523。如何让 Python 抓取字符串直到某个字母或数字? 最佳答案 行 y = x[0:
我想移动拐 Angular 处的方框(从左上角开始水平移动 Angular 落到右上角然后你去到右下角。 function myMove() { var elem = document.getEl
如何让侧边栏停止在第二个侧边栏部分而不是顶部? fiddle http://jsfiddle.net/EvAdP/2/ HTML I'm the header
我刚刚在大学开始我的第二门编程类(class),我们的第一个作业相当简单,旨在基本上检查我们的环境并检查我们是否知道如何通过类(class)网站提交作业。 当我运行我们提供的代码时,它卡在应该提示用户
我目前正忙于我的这个信息学元素(构建一个示例交友网站)。问题是我在把所有东西都放在正确的地方时遇到了一些麻烦。一切都很顺利,直到我的邮箱出现在错误的位置(但是,Dreamweaver 会按照我的意
我想,和你一样hover a GIF shot on Dribbble , 当光标位于元素高度顶部之后/50% 处时显示带有信息的 div。 测试示例 我做了这个,这是有效的,但有点棘手......特
我有一个下拉菜单,并且我已将 mouseenter 设置为选项。因此,如果鼠标位于触发器之外,菜单应该关闭。我正在使用 jQuery 1.8.0。这可能是 CSS 问题吗? 这是我初始化插件的代码。
我正在尝试在 Visual Basic for Applications 中编写一个 hello world 应用程序,即修改 Excel 工作表中的单元格。这是: Sub hello() D
我的应用程序使用 JSF 2.1 和 PrimeFaces。最近,由于一些线程卡住,观察到 CPU 利用率非常高。所有卡住线程的卡住线程转储都指向 javax.faces.component.UICo
在列出 aws cognito 用户时,我的 Node js 应用程序遇到问题。 仅当我有超过 60 个 Cognito 用户时才会出现此问题。 Reference of API 下面是我的代码片段。
我是 ubuntu 用户..我在 php 中有一个执行 python 文件的命令..python 文件设置为可执行文件..所以,我的 php 命令是:- shell_exec("try.py");
我正在尝试将剪贴板内容写入文件,但由于某种原因程序卡住了。 FILE *fp; fp = fopen("tmp.code","w"); fprintf(fp,getclip()); /*writes*
当用户向下滚动时,我使用此代码使侧边栏固定在某个 div 处。问题是我必须手动输入一个阈值数字,这并不总是理想的,因为该部分的位置可能会更改或在各种浏览器和系统之间不一致。我想知道是否有一种方法可以在
我有一个字符串数组,例如 first_page = {{"U","M","Y","Q","I","A","L","D","P"、"F"、"E"、"G"、"T"、"Z"、"V"、"W"、"H"、"O"、
我能否在页面上的特定 px 位置放置一个元素(例如图像),然后让文本围绕它流动? 必要时使用 JS/jquery。 我确实看到了这个Have text flow around an object th
第一次在这里提问。 我有两个简单的 Javascript 函数,1. 生成一个随机字母,2. 在每个单元格中使用单个字母填充 10x10 表格。创建表的主要函数是通过带有 onclick 的简单 HT
我是一名优秀的程序员,十分优秀!