explaingit

zserge/pt

Analysis updated 2026-08-04 · repo last pushed 2016-12-13

308CAudience · developerComplexity · 3/5DormantLicenseSetup · easy

TLDR

A tiny C library that lets functions pause and resume later, so small devices can run several tasks at once without a full operating system or real threads.

Mindmap

mindmap
  root((repo))
    What it does
      Pause and resume functions
      Cooperative multitasking
      Single main loop
    Tech stack
      C language
      Single header file
      Linux and microcontrollers
    Use cases
      Blink LED and read sensor
      Poll buttons and serial
      Producer consumer queue
    Audience
      Embedded developers
      Microcontroller projects
      No OS firmware
    Notable traits
      178 lines of code
      No dynamic memory
      MIT licensed

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Run a firmware loop that polls buttons, services a serial port, and updates a display without an RTOS.

USE CASE 2

Build a producer/consumer system where one task fills a queue and another drains it without either blocking.

USE CASE 3

Juggle multiple jobs on a microcontroller like blinking an LED while reading a sensor.

USE CASE 4

Prototype cooperative multitasking on Linux before deploying to a small device.

What is it built with?

C

How does it compare?

zserge/ptportbuster1337/lpe-toolkitfractalfir/crustc
Stars308328331
LanguageCCC
Last pushed2016-12-132026-07-07
MaintenanceDormantActive
Setup difficultyeasymoderatehard
Complexity3/54/55/5
Audiencedeveloperops devopsdeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 5min

Just include the single header file in your C project, no external dependencies or build configuration needed.

Use freely for any purpose, including commercial and proprietary projects, as long as you keep the copyright notice.

In plain English

pt is a tiny C library that lets a single piece of code pause itself and pick up later right where it left off. This is useful when a small device needs to juggle several jobs at once, like reading a sensor while also blinking an LED, without the overhead of a full operating system. Normally in C, a function runs from top to bottom and then it's done. This library gives you functions that can hit a "wait" point, return to the caller, and resume from that exact spot the next time they're called. You alternate between several of these functions in a loop, and each one makes progress without blocking the others. The README includes a producer/consumer example: one function fills a shared queue when data is ready, another drains it, and neither ever gets stuck waiting. The target audience is embedded developers working on microcontrollers like STM32, AVR, or MSP430, where memory is tight and you can't afford real threads or a full task scheduler. It also runs on Linux if you want to prototype there. A concrete use case is a firmware loop that polls buttons, services a serial port, and updates a display, all from one main loop with no RTOS. What makes it notable is how minimal it is: one header file, 178 lines, nine API functions, and no dynamic memory allocation. It ships with a compact message queue so cooperating tasks can pass data to each other. Compared to similar libraries, it offers a pt_loop construct that runs non-blocking work while waiting, and it stays neutral about scheduling, you decide whether to call tasks in round-robin fashion, nest them, or build something custom. It's MIT-licensed and works in proprietary projects.

Copy-paste prompts

Prompt 1
I have an STM32 firmware project with a single main loop. I need to poll buttons, service a UART port, and update a display without blocking. Show me how to use the pt library to structure these as cooperative tasks that pause and resume.
Prompt 2
Help me implement a producer/consumer pattern using the pt library where one task fills a shared message queue when data arrives and another task drains it, neither ever blocking the other.
Prompt 3
I want to blink an LED and read a sensor on an AVR microcontroller without an RTOS. Write an example using the pt library where both tasks run from one main loop and yield to each other.
Prompt 4
Show me how to use pt_loop to do useful non-blocking work while waiting for a pt task to resume, and explain how I can choose round-robin or custom scheduling for my tasks.

Frequently asked questions

What is pt?

A tiny C library that lets functions pause and resume later, so small devices can run several tasks at once without a full operating system or real threads.

What language is pt written in?

Mainly C. The stack also includes C.

Is pt actively maintained?

Dormant — no commits in 2+ years (last push 2016-12-13).

What license does pt use?

Use freely for any purpose, including commercial and proprietary projects, as long as you keep the copyright notice.

How hard is pt to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is pt for?

Mainly developer.

Open on GitHub → Explain another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.