Author Topic: usleep(1000)  (Read 313 times)

nagibator

  • Newbie
  • *
  • Posts: 7
usleep(1000)
« on: September 13, 2018, 11:30:44 AM »
Hi guys. Currently I'm working on metadata writing app based on Exiftool.  I have some problems with performance and after some debugging I've spotted that this code takes a lot of time:
Code: [Select]
for (;;) {
        cmdNum = mStdout.Read();
        if (cmdNum) break;
        if (getTime() >= doneTime) break;
        if (mCmdQueue) Command();   // keep sending queued commands
        usleep(1000);               // chill and have a beer
    }

Why here execution is blocked for 1000 micro seconds? I've deleted this line and I won ~3 seconds, but I think this line is important, isn't it?

Hayo Baan

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 858
  • Professional Photographer and Workshop Leader
    • Hayo Baan – Photography
Re: usleep(1000)
« Reply #1 on: September 15, 2018, 04:31:08 AM »
Where did you find this piece of code? It's not part of exiftool (which Is 100% Perl, not C).
Hayo Baan – Photography
Web: www.hayobaan.nl
Blog: blog.hayobaan.nl
500px: 500px.com/HayoBaan

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 2036
Re: usleep(1000)
« Reply #2 on: September 15, 2018, 11:30:25 AM »
Looks like it's part of the C++ Interface in the ExifTool.cpp file.
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.

nagibator

  • Newbie
  • *
  • Posts: 7
Re: usleep(1000)
« Reply #3 on: September 17, 2018, 04:55:09 AM »
Where did you find this piece of code? It's not part of exiftool (which Is 100% Perl, not C).
This part of C++ Exiftool interface
Code: [Select]
usleep(1000) //line 718
usleep(100) //line 229

Hayo Baan

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 858
  • Professional Photographer and Workshop Leader
    • Hayo Baan – Photography
Re: usleep(1000)
« Reply #4 on: September 17, 2018, 06:56:04 AM »
It was about time I had a look at the C++ interface, so thank you for your question :)

The sleep of one millisecond is (most likely) there only to prevent burdening the processor continuously with the loop execution. I'm surprised you actually notice this delay (unless you are using a very long list of commands), but it should be safe to make the delay smaller or even zero (though in the latter case one processor core will be used at 100% capacity during the loop run). The change should be made at line 718.

Cheers,
Hayo
Hayo Baan – Photography
Web: www.hayobaan.nl
Blog: blog.hayobaan.nl
500px: 500px.com/HayoBaan

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 13669
    • ExifTool Home Page
Re: usleep(1000)
« Reply #5 on: September 17, 2018, 07:52:49 AM »
Yes.  That delay is there just to prevent the process from using 100% of the CPU when it is doing nothing.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

nagibator

  • Newbie
  • *
  • Posts: 7
Re: usleep(1000)
« Reply #6 on: September 24, 2018, 05:19:53 AM »
Thanks guys!