How can I use "Thread-safety"?

91 views
Skip to first unread message

tomosa

unread,
Jun 2, 2011, 10:42:51 PM6/2/11
to tesseract-ocr
Hello.

I use the Tesseract V3.01 code "tesseract-ocr-read-only".
According to its ReleaseNotes, it seems to be able to use "Thread-
safety".

I want to mount the multithread processing at the page level.
That is, I want to make each thread work for each page at the same
time.

Now I mount it with OpenMP, but it doesn't operate well.
Segmentation fault is always generated.
Where is the place of "Thread-safety" in the source code?
How can I use "Thread-safety"?

Will you show me your idea if you can use "Thread-safety"?

Thanks.

tomosa

Francesco Visconti

unread,
Mar 11, 2015, 6:41:21 AM3/11/15
to tesser...@googlegroups.com
Hi tomosa,
I have exactly the same questions, but I'm using tesseract 3.03 rc1.
I'm trying to use openmp to process one page per thread; so far, I just modified the ProcessPages code like this:

if (npages > 0) {

    pixDestroy(&pix);

//francesco

//modified to use omp:

//define lpage = local page variable to initialize the loop;

//modify branch logic to exclude break statement

#pragma omp parallel for private(pix) 

    for (int lpage = page; lpage < npages; ++lpage) {

      // only use opencl if compiled w/ OpenCL and selected device is opencl

#ifdef USE_OPENCL

      if ( od.selectedDeviceIsOpenCL() ) {

        pix = od.pixReadTiffCl(filename, lpage);

      } else {

#endif

        pix = pixReadTiff(filename, lpage);

#ifdef USE_OPENCL

      }

#endif


      if (pix == NULL) //was break. Now it keeps cycling doing nothing useful

        bool dummy_var = true;

      else{

        if ((lpage >= 0) && (npages > 1))

          tprintf("Page %d of %d\n", lpage + 1, npages);

        char page_str[kMaxIntSize];

        snprintf(page_str, kMaxIntSize - 1, "%d", lpage);

        SetVariable("applybox_page", page_str);

        success &= ProcessPage(pix, lpage, filename, retry_config,

                             timeout_millisec, renderer);

        pixDestroy(&pix);

      }

      //commented out

     /* if (tesseract_->tessedit_page_number >= 0 || npages == 1) {

        break;

      }*/

    } 

I got segfault too, and debugging via gdb I found the problem here - a short backtrace follows:

#0  0x00007ffff7829779 in ELIST_ITERATOR::forward (this=0x7fffffffb4d0) at elst.cpp:237

#1  0x00007ffff7640648 in C_BLOB_IT::forward (this=0x7fffffffb4d0) at ../ccstruct/stepblob.h:28

#2  0x00007ffff776356a in assign_blobs_to_blocks2 (pix=0x83f530, blocks=0x7fffdc000960, 

    port_blocks=0x7fffffffb950) at tordmain.cpp:173


Moreover, I tried to run the code under valgrind with the drd tool, and I got a ton of conflicts.
It seems it really can't be the correct approach, we really need the help of a staff member here!


f.

Reply all
Reply to author
Forward
0 new messages