Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows API
  4. Multithreading and timing with Windows API

Multithreading and timing with Windows API

Scheduled Pinned Locked Moved Windows API
jsontutorialquestion
2 Posts 2 Posters 6 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Ninimi
    wrote on last edited by
    #1

    Hi, Being a newbie in multithreading concept, I'd like to better understand why multithreading and/or multi-cores CPU could be problematic while determining timing in a program. Suppose, for example, that I want to know the elapsed time since a user has clicked with a mouse on the PC screen. I understand that there should be an event handler, but I read on some websites that computing such a deltatime could be very tricky, especially for multithreading and/or multi-cores PC. On the other hand, some people warns about using GetPerformanceCounter because of the multithreading and/or multi-cores... I would like to understand why and the concepts behind ? Thank you a lot,

    Niaina

    P 1 Reply Last reply
    0
    • N Ninimi

      Hi, Being a newbie in multithreading concept, I'd like to better understand why multithreading and/or multi-cores CPU could be problematic while determining timing in a program. Suppose, for example, that I want to know the elapsed time since a user has clicked with a mouse on the PC screen. I understand that there should be an event handler, but I read on some websites that computing such a deltatime could be very tricky, especially for multithreading and/or multi-cores PC. On the other hand, some people warns about using GetPerformanceCounter because of the multithreading and/or multi-cores... I would like to understand why and the concepts behind ? Thank you a lot,

      Niaina

      P Offline
      P Offline
      pasztorpisti
      wrote on last edited by
      #2

      The first problem is that your thread might be executed by different cores, the OS might switch your thread from one core to another. There are several problems with this: the switch takes time, it might screw up per-core cache efficiency and another problem is that GetPerformanceCounter() uses the tick count of the processor that said to be problematic on some systems if your thread is jumping from one core to another. To force the execution of your thread to a specific core use SetThreadAffinityMask()[^]. With this you might want to force every thread in your program to a specific core to avoid the problems I described above.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups