我被分配了一个任务,因此使用信号、setjmp 和 longjmp c 函数模拟用户级线程库。基本上,该程序包括为每个“线程”分配内存,并使用长跳转和信号来模拟非直接代码流和抢占。
当我运行 valgrind 工具时,我收到以下形式的消息:“””
Invalid write of size 8
==19100== at 0x560020F: __sigsetjmp (setjmp.S:36)
==19100== by 0x403EC3: switchThreads(bool, bool, bool) (uthreads.cpp:673)
==19100== by 0x403DE6: signalHandler(int) (uthreads.cpp:652)
==19100== by 0x56004EF: ??? (in /lib/x86_64-linux-gnu/libc-2.13.so)
==19100== by 0x404D93: t1() (tal3.cpp:23)
==19100== Address 0x5959c90 is 48 bytes inside a block of size 4,312 alloc'd
==19100== at 0x4C2851B: operator new(unsigned long, std::nothrow_t const&) (vg_replace_malloc.c:316)
==19100== by 0x402E67: uthread_spawn(void (*)()) (uthreads.cpp:358)
==19100== by 0x404DD6: main (a3.cpp:41)
"""
我已经阅读了该工具的一些论坛和文档,据我了解,valgrind 似乎不支持长跳转和“setjmp”(只要信号处理跳转),因此导致似乎是内存问题 -但我无法给出明确的答案。
感谢您的帮助。谢谢。