Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 36039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T14:19:50+00:00 2026-05-10T14:19:50+00:00

On Windows I have a problem I never encountered on Unix. That is how

  • 0

On Windows I have a problem I never encountered on Unix. That is how to get a thread to sleep for less than one millisecond. On Unix you typically have a number of choices (sleep, usleep and nanosleep) to fit your needs. On Windows, however, there is only Sleep with millisecond granularity.

On Unix, I can use the use the select system call to create a microsecond sleep which is pretty straightforward:

int usleep(long usec) {     struct timeval tv;     tv.tv_sec = usec/1000000L;     tv.tv_usec = usec%1000000L;     return select(0, 0, 0, 0, &tv); } 

How can I achieve the same on Windows?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T14:19:51+00:00Added an answer on May 10, 2026 at 2:19 pm

    On Windows the use of select forces you to include the Winsock library which has to be initialized like this in your application:

    WORD wVersionRequested = MAKEWORD(1,0); WSADATA wsaData; WSAStartup(wVersionRequested, &wsaData); 

    And then the select won’t allow you to be called without any socket so you have to do a little more to create a microsleep method:

    int usleep(long usec) {     struct timeval tv;     fd_set dummy;     SOCKET s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);     FD_ZERO(&dummy);     FD_SET(s, &dummy);     tv.tv_sec = usec/1000000L;     tv.tv_usec = usec%1000000L;     return select(0, 0, 0, &dummy, &tv); } 

    All these created usleep methods return zero when successful and non-zero for errors.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an intermittent problem with some code that writes to a Windows Event
I encountered an interesting thing today that I have never noticed before. It appears
I have encountered a rather nasty problem with the DataGridView control (Windows.Forms, .NET Framework
I have a problem in a Windows Forms application with Bitmap.Save failing when I
I have a problem with a ClickOnce deployment of a Windows Forms application. When
I have a windows service installed using installutil and set to Autostart. My problem
I have a little demonstration below of a peculiar problem. using System; using System.Windows.Forms;
This is a problem I have encountered several times over the years, and I
I have problems with bringing a windows mobile 6 form to the front. I
I have some problems with Miktex installed on Windows Vista Business SP1/32 bit. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.