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. C#
  4. Platform dependency of thread management

Platform dependency of thread management

Scheduled Pinned Locked Moved C#
linuxiottutorialquestion
2 Posts 2 Posters 0 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.
  • B Offline
    B Offline
    Bernhard Hiller
    wrote on last edited by
    #1

    A Thread.Sleep(n) will pause the current thread for at least n milliseconds. But there are some caveats: Thread.Sleep(1) takes at least some 15 ms on "common" Windows 7/8/10 due to the "time slice" management of threads. In contrast, running the same code with mono on Linux, the sleep time may get close to 1 ms. I haven't found any information on Windows 10 IoT for that feature. Already this simple example shows that Threads are dealt with differently depending on the underlying platform. Where can I find more information on that feature? The main interest is differences between Windows 10 Pro and Windows 10 IoT, but also information beyond that is appreciated.

    Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!

    D 1 Reply Last reply
    0
    • B Bernhard Hiller

      A Thread.Sleep(n) will pause the current thread for at least n milliseconds. But there are some caveats: Thread.Sleep(1) takes at least some 15 ms on "common" Windows 7/8/10 due to the "time slice" management of threads. In contrast, running the same code with mono on Linux, the sleep time may get close to 1 ms. I haven't found any information on Windows 10 IoT for that feature. Already this simple example shows that Threads are dealt with differently depending on the underlying platform. Where can I find more information on that feature? The main interest is differences between Windows 10 Pro and Windows 10 IoT, but also information beyond that is appreciated.

      Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Worse yet, Thread.Sleep doesn't even guarantee that the thread will actually give up its time slice. If there are no other threads ready to run at the same priority, your Thread is not suspended. T minimum time a Thread can "sleep" is dependent on the system timer and its resolution. The timer is dependent on hardware and O/S implementation. From the Sleep function[^] in the Win32 documentation:

      Quote:

      The system clock "ticks" at a constant rate. If dwMilliseconds is less than the resolution of the system clock, the thread may sleep for less than the specified length of time. If dwMilliseconds is greater than one tick but less than two, the wait can be anywhere between one and two ticks, and so on. To increase the accuracy of the sleep interval, call the timeGetDevCaps function to determine the supported minimum timer resolution and the timeBeginPeriod function to set the timer resolution to its minimum. Use caution when calling timeBeginPeriod, as frequent calls can significantly affect the system clock, system power usage, and the scheduler. If you call timeBeginPeriod, call it one time early in the application and be sure to call the timeEndPeriod function at the very end of the application.

      Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
      Dave Kreskowiak

      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