mx_task

A simple to use MATLAB library for "real-time" multi-tasking.

https://github.com/carl0sma/mx_task

You are now following this Submission

# mx_task
A simple to use MATLAB library for "real-time" multi-tasking.

Multitasking with tic-toc and robotics.Rate require full CPU usage which is sometimes undesired.

The new mx_task class allows users to achieve an almost real-time multitasking functionality in MATLAB, whilst not requiring full CPU usage.

---
Supports Linux and Windows. Linux systems generally have a better RT behaviour.

Functionality verified on:
- a 18.04LTS machine with MATLAB R2016b and R2019a,
- a Windows 10 machine with MATLAB R2018b.

Example 0 shows the basic functionalities of the mx_task library.

Example 1 shows how to implement multi-tasking.

Example 2 is a benchmarking script for comparisons between the scheduling capabilities of mx_task, tictoc, and robotics.Rate.

# Usage
1. First define a task with a function and affix it to a new mx_task instance. Define the desired task period at the second input.

myTask = mx_task(@()myFunc, 1/10);

function myFunc()

fprintf("Hello world.\n");

end

2. Capture the start time in [seconds since epoch] with mx_sleep().

time_start = mx_sleep(0); % sleeps for 0 seconds

time_now = time_start;

3. Create a while loop with a simulation time trap in the condition. mx_sleep for 1us for an almost real-time scheduling quality. Run task by task.run(time_now).

while (time_now <= time_start + 10) % run tasks for 10 seconds.

time_now = mx_sleep(1/1000000); % 1MHz scheduler frequency. Set to mx_sleep(0) for an enhanced real-time behaviour (at 100% CPU though).

myTask.run(time_now);

end

# Installation
Move to the mx_task directory and run the install script.

Cite As

Carlos Ma (2026). mx_task (https://github.com/carl0sma/mx_task), GitHub. Retrieved .

General Information

MATLAB Release Compatibility

  • Compatible with R2016b to R2019a

Platform Compatibility

  • Windows
  • macOS
  • Linux

Versions that use the GitHub default branch cannot be downloaded

Version Published Release Notes Action
1.0.2

Validated Windows compatibility. A Linux system is still recommended for superior RT performances.

1.0.1

Validated Windows support, although its RT behaviour is much worse than at on a Linux system.

1.0.0

To view or report issues in this GitHub add-on, visit the GitHub Repository.
To view or report issues in this GitHub add-on, visit the GitHub Repository.