sc/condition
Tezc 950d6f191b
Build test on debug only (#45)
* Build tests in debug mode only, fix gcc warnings
* strncpy fix in thread err
2021-02-16 04:23:08 +03:00
..
2021-02-06 21:36:18 +03:00
2021-02-07 20:42:08 +03:00
2021-02-07 22:31:04 +03:00
2021-02-16 04:23:08 +03:00
2021-02-14 16:19:26 +03:00

Condition

Overview

  • Condition wrapper.
  • Provides passing data between signal and wait threads.
  • 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', so 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()
{
    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;
}