sc/condition
Sergi Vladykin 2fa40dd436
Zig CC cross-compilation support for Windows on Linux host. (#128)
Zig CC cross-compilation support for Windows on Linux host
2023-12-21 10:50:39 +03:00
..
2022-12-07 00:55:43 +03:00
2023-03-19 21:54:21 +03:00
2022-08-20 18:56:21 +03:00
2023-06-03 00:37:11 +03:00

Condition

Overview

  • Condition wrapper for Posix and Windows.
  • Normally, if no thread waits on a condition, signal is missed. This
    implementation differs as it will keep a result variable when 'signal' is
    called. Signal will mark the condition 'done'. When another thread calls
    wait(), it won't be blocked, it will return immediately with the user
    provided data.

Usage

#include "sc_cond.h"

#include <stdio.h>

int main(void)
{
    struct sc_cond cond;

    sc_cond_init(&cond); // Init once
    
    sc_cond_signal(&cond, "test"); // Call this on thread-1
    char *p = sc_cond_wait(&cond); // Call this on another thread.

    printf("%s \n", p); // Prints "test"
    
    sc_cond_term(&cond); // Destroy

    return 0;
}