how to schedule threads for time

Posted on 2006-04-03
Last Modified: 2008-02-07
Hi I'm using pthreads. I've have not been able to find a examples showing how to schedule thread execution based on time. For example if i want a thread to run every 100ms. Can anyone point me to some good example code.
Question by:BlackRussian
    LVL 43

    Expert Comment

    It's in fact impossible under linux. Linux does not guarantee You any timings.
    What You need is real time scheduling - try

    Or maybe You just need to do something, then sleep for about 100ms, then do something else and so on?
    You could make one of threads a scheduler, which would trigger other threads(mutex, waitqueue, etc.) at given time points...
    LVL 23

    Accepted Solution

    This is typically done by having the thread's run routine be a loop that sleeps for 100ms on each iteration:

    while(1) {

    If your system does not support a thread-safe usleep, you could use pthread_cond_timedwait() instead by createing a private condition variable that noone will ever signal.
    LVL 43

    Expert Comment

    excuse me - You haven'k know the usleep() function?
    Maybe You should then ask - how to sleep for 100ms....

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
    The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now