Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
timeoutQueue_example.C File Reference

Example demonstrating TimeoutQueue usage for timed event scheduling. More...

#include <iostream>
#include <iomanip>
#include <sstream>
#include <atomic>
#include <chrono>
#include <thread>
#include <timeoutQueue.H>
Include dependency graph for timeoutQueue_example.C:

Go to the source code of this file.

Classes

class  SimpleEvent
 
class  NumberedEvent
 
class  CancellableEvent
 
class  ReschedulableEvent
 
class  PeriodicEvent
 
class  CallbackEvent
 

Functions

static Time time_from_now_ms (int ms)
 
static string format_time (const Time &t)
 
static string now_str ()
 
void demo_simple_event (TimeoutQueue &queue)
 
void demo_priority_ordering (TimeoutQueue &queue)
 
void demo_cancellation (TimeoutQueue &queue)
 
void demo_rescheduling (TimeoutQueue &queue)
 
void demo_periodic_event (TimeoutQueue &queue)
 
void demo_callback_event (TimeoutQueue &queue)
 
void print_status (const TimeoutQueue::Event *e, const string &name)
 
void demo_event_status (TimeoutQueue &queue)
 
void demo_cancel_delete (TimeoutQueue &queue)
 
int main ()
 

Detailed Description

Example demonstrating TimeoutQueue usage for timed event scheduling.

TimeoutQueue - Priority-based timed event scheduler

This example demonstrates:

  • Basic event scheduling with absolute times
  • Event cancellation and rescheduling
  • Multiple events with different trigger times
  • Event lifecycle management
  • Shutdown behavior

Key Concepts

  • Event: Derive from TimeoutQueue::Event and override EventFct()
  • Scheduling: Events execute when their trigger time arrives
  • Thread-safe: All operations are protected by mutex
  • Background thread: Monitors queue and triggers events

Compilation

g++ -std=gnu++20 -O2 -I.. -pthread -o timeoutQueue_example \
timeoutQueue_example.C ../timeoutQueue.C ../useMutex.C -lpthread

Usage

./timeoutQueue_example

Definition in file timeoutQueue_example.C.

Function Documentation

◆ demo_callback_event()

void demo_callback_event ( TimeoutQueue queue)

Definition at line 317 of file timeoutQueue_example.C.

References Aleph::maps(), now_str(), TimeoutQueue::schedule_event(), and time_from_now_ms().

Referenced by main().

◆ demo_cancel_delete()

void demo_cancel_delete ( TimeoutQueue queue)

◆ demo_cancellation()

◆ demo_event_status()

void demo_event_status ( TimeoutQueue queue)

◆ demo_periodic_event()

void demo_periodic_event ( TimeoutQueue queue)

Definition at line 282 of file timeoutQueue_example.C.

References Aleph::maps(), now_str(), TimeoutQueue::schedule_event(), and time_from_now_ms().

Referenced by main().

◆ demo_priority_ordering()

void demo_priority_ordering ( TimeoutQueue queue)

Definition at line 129 of file timeoutQueue_example.C.

References Aleph::maps(), now_str(), TimeoutQueue::schedule_event(), and time_from_now_ms().

Referenced by main().

◆ demo_rescheduling()

void demo_rescheduling ( TimeoutQueue queue)

◆ demo_simple_event()

void demo_simple_event ( TimeoutQueue queue)

Definition at line 96 of file timeoutQueue_example.C.

References Aleph::maps(), now_str(), TimeoutQueue::schedule_event(), and time_from_now_ms().

Referenced by main().

◆ format_time()

static string format_time ( const Time t)
static

Definition at line 53 of file timeoutQueue_example.C.

References Aleph::maps().

◆ main()

◆ now_str()

◆ print_status()

void print_status ( const TimeoutQueue::Event e,
const string &  name 
)

◆ time_from_now_ms()