infix
A JIT-Powered FFI Library for C
Loading...
Searching...
No Matches
Ch04_ThreadSafety.c File Reference

Cookbook Chapter 4: Proving Thread Safety. More...

#include <infix/infix.h>
#include <stdio.h>
#include <pthread.h>
Include dependency graph for Ch04_ThreadSafety.c:

Classes

struct  thread_data_t
 

Functions

static int add (int a, int b)
 
void * worker_thread_func (void *arg)
 
int main ()
 

Detailed Description

Cookbook Chapter 4: Proving Thread Safety.

This example demonstrates that infix trampoline handles are thread-safe. A trampoline handle (infix_forward_t* or infix_reverse_t*) is immutable after creation and can be safely shared between threads. All mutable state (like error details) is stored in thread-local storage, so calls from different threads will not interfere with each other.

This recipe creates a trampoline on the main thread and passes its callable function pointer to a worker thread, which then executes the FFI call.

Function Documentation

◆ add()

static int add ( int  a,
int  b 
)
static

◆ main()

int main ( void  )

◆ worker_thread_func()

void * worker_thread_func ( void *  arg)