...
while(!paintQueue.empty()) paintQueue.pop();
for(int i=1;i<=cnt;i++){
paintQueue.push(pointToPaint[i].point);
}
...
上面是队列操作的代码,同时有多线程操作队列。
多线程代码如下:
...
lock_guard<mutex> lk(mtx);
clock_t startClock = clock() / (CLOCKS_PER_SEC / 1000);
Point p = paintQueue.front();
paintQueue.pop();
mtx.unlock();
...
上述代码导致 SIGABRT,具体报错如下:
main(69716,0x1ee23de00) malloc: Corruption of free object 0x13d708280: msizes 32/1088 disagree
main(69716,0x1ee23de00) malloc: *** set a breakpoint in malloc_error_break to debug
zsh: abort (core dumped) ./main
调试 core 文件取得信息如下:
* thread #1
* frame #0: 0x000000019322c724 libsystem_kernel.dylib`__pthread_kill + 8
frame #1: 0x0000000193263c28 libsystem_pthread.dylib`pthread_kill + 288
frame #2: 0x0000000193171ae8 libsystem_c.dylib`abort + 180
frame #3: 0x0000000193092e28 libsystem_malloc.dylib`malloc_vreport + 908
frame #4: 0x00000001930a95d4 libsystem_malloc.dylib`malloc_zone_error + 104
frame #5: 0x00000001930a9354 libsystem_malloc.dylib`_tiny_check_and_zero_inline_meta_from_freelist + 188
frame #6: 0x0000000193087ea8 libsystem_malloc.dylib`tiny_malloc_from_free_list + 440
frame #7: 0x0000000193087670 libsystem_malloc.dylib`tiny_malloc_should_clear + 216
frame #8: 0x000000019308624c libsystem_malloc.dylib`szone_malloc_should_clear + 92
frame #9: 0x000000010315b62c libstdc++.6.dylib`operator new(unsigned long) + 28
frame #10: 0x0000000100cd7cdc main`std::__new_allocator<Point>::allocate(unsigned long, void const*) + 132
frame #11: 0x0000000100cd61a8 main`std::_Deque_base<Point, std::allocator<Point> >::_M_allocate_node() + 196
frame #12: 0x0000000100cd4da0 main`void std::deque<Point, std::allocator<Point> >::_M_push_back_aux<Point const&>(Point const&) + 112
frame #13: 0x0000000100cd322c main`std::deque<Point, std::allocator<Point> >::push_back(Point const&) + 132
frame #14: 0x0000000100cd05ac main`std::queue<Point, std::deque<Point, std::allocator<Point> > >::push(Point const&) + 28
frame #15: 0x0000000100ccdee8 main`main + 3152
frame #16: 0x0000000192f0bf28 dyld`start + 2236
注:出错代码通过调试信息得来。