gpt4 book ai didi

c - 使用 malloc/free 时的 __lll_lock_wait_private ()

转载 作者:行者123 更新时间:2023-11-30 17:12:19 26 4
gpt4 key购买 nike

我有一个用户级线程库,并且我更改了一个基准程序以使用 mythreads 而不是 pthreads,但它总是卡在代码中存在 malloc 或 free 函数的某个位置。

这是 gdb 的输出:

^C
Program received signal SIGINT, Interrupt.
__lll_lock_wait_private ()
at ../sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:95
95 ../sysdeps/unix/sysv/linux/x86_64/lowlevellock.S: No such file or directory.
(gdb) where
#0 __lll_lock_wait_private ()
at ../sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:95
#1 0x00007ffff7569bb3 in _int_free (av=0x7ffff78adc00 <main_arena>,
p=0x6f1f40, have_lock=0) at malloc.c:3929
#2 0x00007ffff756d89c in __GI___libc_free (mem=<optimized out>)
at malloc.c:2950
#3 0x000000000040812d in mbuffer_free (m=m@entry=0x6a7660) at mbuffer.c:209
#4 0x00000000004038a8 in write_chunk_to_file (chunk=0x6a7610,
fd=<optimized out>) at encoder.c:279
#5 Reorder (targs=0x7fffffffab60,
targs@entry=<error reading variable: value has been optimized out>)
at encoder.c:1292
#6 0x000000000040b069 in wrapper_function (func=<optimized out>,
arg=<optimized out>) at gtthread.c:75
#7 0x00007ffff7532620 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#8 0x0000000000000000 in ?? ()
(gdb)

这是一些代码

mbuffer.c
208 if(ref==0) {
209 pausee();
210 free(m->mcb->ptr);
211 resume();
212 m->mcb->ptr=NULL;
213 free(m->mcb);
214 m->mcb=NULL;
215 }

暂停和恢复功能

void pausee(){
//printf("pauseeing\n");
sigemptyset(&mask);
sigaddset(&mask, SIGPROF); // block SIGPROF...
if (sigprocmask(SIG_BLOCK, &mask, &orig_mask) < 0) {
perror ("sigprocmask");
exit(1);
}
}
void resume(){
//printf("restarting\n");
sigemptyset(&mask);
sigaddset(&mask, SIGPROF); // unblock SIGPROF...
if (sigprocmask(SIG_SETMASK, &orig_mask, NULL) < 0) {
perror ("sigprocmask");
exit(1);
}
}

我不确定它是否与我的问题有关,但为了调度线程,我使用 SIGPROF 信号和处理函数。我尝试在每个 malloc/free 函数之前阻止 SIGPROF,但没有效果。

我没有任何并发​​线程,一次只有一个线程运行。

任何帮助或想法将不胜感激。

最佳答案

作为你的代码mbuffer.c,没有错误。我建议你对mbuffer.c进行测试,除了你的猜测。

关于c - 使用 malloc/free 时的 __lll_lock_wait_private (),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31634255/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com