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 8842587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:59:46+00:00 2026-06-14T10:59:46+00:00

I am aware that there are available functions and libraries that allow concurrency in

  • 0

I am aware that there are available functions and libraries that allow concurrency in c.

(pthread.h, fork() etc.)

However, I was wondering if there is any way to simulate concurrency in C, without actually having to use more than one thread?

Example scenario:

There is a main program loop running and outputting calculations. Somehow another function notifies the main function that the time is now 12:00 p.m. and the program should stop outputting calculations as the user is going off to lunch. At 12:30 this function notifies the main function to start outputting calculations again.

Can someone point me in the right direction on how to do this?

EDIT:

In essence I believe there should be 2 ways to do this:

The first would be the main program constantly checking the alternate function so it knows when the clock hits 12:00. (this is very simple and I know how to do this)

The second would be having the alternate function contact the main program whenever required (i.e. at 12:00 and 12:30).

  • 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-06-14T10:59:48+00:00Added an answer on June 14, 2026 at 10:59 am

    It seems to me like you just need a simple timer you could use alarm() for that:

    #include <signal.h>
    #include <stdio.h>
    #include <unistd.h>
    
    volatile unsigned stop_working = 0;
    
    void alarm_handler(int signum)
    {
        stop_working = 1;
        //alarm(1); //reschedule alarm
    }
    
    int main()
    {        
        signal(SIGALRM, alarm_handler);
        alarm(1); //schedule alarm in seconds
    
        while (!stop_working) {
          //do some work
        }
    }
    

    If however, you want to have something like coroutines you should look into user-level threads (or fibers) using functions like makecontext() and swapcontext()

    Note: this example is UNIX/Linux specific, for MinGW you will need to use winapi, using functions like CreateWaitableTimer(), SetWaitableTimer(), and so on. See MSDN for details.

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

Sidebar

Related Questions

I'm aware that there are several Cocoa Touch/iPhone calendar implementations available online, but for
I'm well aware that there are only two available UIView transitions, UIViewAnimationTransitionFlipFromLeft and UIViewAnimationTransitionFlipFromRight.
I am aware that there is a similar question here with no solution. I'm
Now, I am aware that there is no such thing as exiting an app
I'm trying to find eveything inside a div using regexp. I'm aware that there
I'm very new to SCM, and I'm aware that there are some guidlines and
There are three Timer classes that I am aware of, System.Threading.Timer , System.Timers.Timer ,
I am aware that MD5 hashes are not advisable for security any more but
I am aware that there is something special about tapestry services/resources such as Request,
Are there any open-source tools available which support searching for Java methods by the

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.