opencv: cv::Mat clone or copyTo caused crash or hanging under multi-threads contexts even use different variables

System information (version)
  • OpenCV => 4.5.0
  • Operating System / Platform => Linux armv7l 32bit
  • Compiler => buildroot gcc 6.5.0 with glibc 2.29-11-ge28ad442e73b00ae2047d89c8cc7f9b2a0de5436
Detailed description

#####Hi, I have stucked by this issue for some days, call cv::Mat clone(or copyTo) more than two threads will cause randomly crash and the stack is corrupted, below is one of the sample crash(sometimes crash at copy.cpp 302): warning: Unable to find libthread_db matching inferior’s thread library, thread debugging will not be available. Core was generated by `./demo_crash’. Program terminated with signal SIGSEGV, Segmentation fault. #0 0xb6e9abe0 in ?? () from /usr/lib/libstdc++.so.6 [Current thread is 1 (LWP 668)] (gdb) bt full #0 0xb6e9abe0 in ?? () from /usr/lib/libstdc++.so.6 No symbol table info available. #1 0xb6c3a054 in ?? () from /lib/libc.so.6 No symbol table info available. Backtrace stopped: previous frame identical to this frame (corrupt stack?)

I attached sample code which can be reproduced on our platform, pls help to check is there something I doing wrong. test001.jpg is just one 800x600 jpg file, arbitrary image can reproduce this issue. tks.

void * thread_main_entry(void *pic_name) { printf(“thread_main_entry start!\n”); //cv::setNumThreads(0); while(true) { cv::Mat _rgb; cv::Mat _bgr; cv::Mat _gray; cv::Mat frame; printf(“pic file name is: %s\n”, (char *)pic_name); while (true) { frame = cv::imread((char *)pic_name, 1); if(!frame.empty()) break; } printf(“clone begin: %d\n”, LINE); _bgr = frame.clone(); printf(“clone end: %d\n”, LINE); cv::cvtColor(_bgr, _rgb, cv::COLOR_BGR2RGB); printf(“convert1 end: %d\n”, LINE); cv::cvtColor(_bgr, _gray, cv::COLOR_BGR2GRAY); printf(“convert2 end: %d\n”, LINE); } }

Demo* Demo::instance = NULL; int main(int argc, char **argv) { //signal(SIGSEGV, signal_handler); //signal(SIGABRT, signal_handler); //signal(SIGILL, signal_handler); //signal(SIGBUS, signal_handler); //Demo::instance = new Demo(); //Demo::instance->start(); //delete Demo::instance;

pthread_t thread_id1, thread_id2, thread_id3, thread_id4;
int ret ,stacksize = 8192000;
pthread_attr_t attr;
ret = pthread_attr_init(&attr);
if (ret != 0)
    return -1;
ret = pthread_attr_setstacksize(&attr, stacksize);
if(ret != 0)
    return -1;
ret = pthread_create (&thread_id1, &attr, &thread_main_entry, (void *)"test001.jpg");
if(ret != 0)
    return -1;
ret = pthread_create (&thread_id2, &attr, &thread_main_entry, (void *)"test001.jpg");
if(ret != 0)
    return -1;
ret = pthread_create (&thread_id3, &attr, &thread_main_entry, (void *)"test001.jpg");
if(ret != 0)
    return -1;
ret = pthread_create (&thread_id4, &attr, &thread_main_entry, (void *)"test001.jpg");
if(ret != 0)
    return -1;
ret = pthread_attr_destroy(&attr);
if(ret != 0)
    return -1;
if ( pthread_join ( thread_id1, NULL ) ) {
    printf("error join thread.\n");
    return -1;
}
if ( pthread_join ( thread_id2, NULL ) ) {
    printf("error join thread.\n");
    return -1;
}
if ( pthread_join ( thread_id3, NULL ) ) {
    printf("error join thread.\n");
    return -1;
}
if ( pthread_join ( thread_id4, NULL ) ) {
    printf("error join thread.\n");
    return -1;
}
return 0;

}

Issue submission checklist
  • I report the issue, it’s not a question
  • I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found solution
  • I updated to latest OpenCV version and the issue is still there
  • There is reproducer code and related data files: videos, images, onnx, etc

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (3 by maintainers)

Most upvoted comments

It’s our platform DDR configuration issues, not opencv bug or other 3rd party packages’s bug, I will close this issue, tks so much for your help.