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

  • SEARCH
  • Home
  • 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 4618200
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:13:56+00:00 2026-05-22T02:13:56+00:00

Could your please help me with following interview question. Given function ‪ Sleep(int seconds)

  • 0

Could your please help me with following interview question.

Given function ‪Sleep(int seconds) implement following interface so timers could be used:

  • function ‪void CreateTimer(void (*func)(), int seconds) that her purpose is to create timer
  • function ‫‪void StartTimers() that her purpose to start all the timers

Every timer that started should delay for several seconds and then use a callback to call a function.
Example:

CreateTimer(func1,3);
CreateTimer(func2,7);
CreateTimer(func3,10);
StartTimers()

The folowing should be happening:

Delay for 3 seconds and then call for function 1.
Delay for 4 seconds and then call for function 2.
Delay for 3 seconds and then call for function 3.

The question is how implement such interface?

  • 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. Editorial Team
    Editorial Team
    2026-05-22T02:13:57+00:00Added an answer on May 22, 2026 at 2:13 am

    EDIT 1: Use the questions API.

    EDIT 2: Oops, didn’t call q.pop();

    This sounds like a job for std::priority_queue, ordered by deadline.

    //pseudo-code
    class Job;
    std::priority_queue<Job, std::vector<Job>, CompareLessByDeadline> q;
    
    CreateTimer(func, deadline) {
       q.push(Job(func, deadline));
    }
    StartTimers() {
      now = 0;
      while(!q.empty()) {
        Job& j = q.top();
        Sleep(j.deadline-now);
        now = j.deadline;
        j.function();
        q.pop();
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want your suggestion on the following pseudo-code. Please suggest how could I improve
Could you please help me? Following code sample: public abstract class AbstractWorker { public
Could someone tell me what the units the SetTimeout(int) method in the ICriteria interface
Could someone please help me to compile my .c file with MSVC++6 in windows
could you please help me with this code? <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0
Could you please help me to understand the difference from a private method and
Could someone here please help me understand how to determine when floating point limitations
Good day. I could really use your help on this one. I have a
I just wanted to see if I could have your thoughts on the design
Depends on your experience could you recommend something? I've use izpack , and it's

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.