sc/condition/README.md

36 lines
801 B
Markdown
Raw Normal View History

2020-12-27 16:02:35 +03:00
# Condition
#### Overview
- Condition wrapper.
2021-02-03 08:09:50 +03:00
- 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.
2020-12-27 16:02:35 +03:00
##### Usage
```c
#include "sc_cond.h"
#include <stdio.h>
int main()
{
struct sc_cond cond;
2021-02-06 21:36:18 +03:00
sc_cond_init(&cond); // Init once
2020-12-27 16:02:35 +03:00
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"
2021-02-06 21:36:18 +03:00
sc_cond_term(&cond); // Destroy
2020-12-27 16:02:35 +03:00
return 0;
}
2021-02-06 21:36:18 +03:00
2020-12-27 16:02:35 +03:00
```