Re: triggering an event every 5 minutes in C

From: John Smith (john.smith_at_x-formation.com)
Date: 03/15/05


Date: Tue, 15 Mar 2005 18:26:36 +0100


> I am trying to figure out what the best way to have my program do
> something (change the value of a variable) every x number of minutes. Can
> somebody give me a pointer in the right direction? I am writing in C in
> a linux environment.
>

One way is to start a thread, sleep for 5 mins, change the variable and go
to sleep again.

Look into pthreads (threads and mutex since you need to have to establish a
lock between the threads accessing your variable).

-- John



Relevant Pages

  • Re: Locking etc. (Long, boring, redundant, newbie questions)
    ... What is really meant is that depending on the type of mutex a thread is trying to acquire, the thread will either spin or it will sleep waiting for the lock to become available. ...
    (freebsd-hackers)
  • Locking etc. (Long, boring, redundant, newbie questions)
    ... sleep waiting for the lock to become available. ... mutex protects. ... if we spin for so long ...
    (freebsd-hackers)
  • RE: Do you really "sleep" when blocked on a mutex?
    ... means that if a thread is holding a lock, ... Do you really "sleep" when blocked on a mutex? ... sched_wakeup which eventually calls setrunqueue()? ...
    (freebsd-hackers)
  • Re: Recursive mutex that can be waited upon (pthread)
    ... on an object, you are releasing the lock to the object, hence of course ... If Thread 1 kept the lock when going to sleep, ... I'm trying to avoid spin-locks basically. ... *mutex* threads use to synchronize access to that data. ...
    (comp.programming.threads)
  • Re: witness oddity
    ... >> back in during which time your mutex will continue to be held. ... > being in a deadlock with the vm map lock. ... or sleep?) ... copyouttakes a page fault it can sleep, so holding a mutex across copy* ...
    (freebsd-current)