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

A "barebones" thread-safety test with no testing framework dependency. More...

#include "common/infix_config.h"
#include <infix/infix.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <pthread.h>
Include dependency graph for 821_threading_bare.c:

Macros

#define NUM_THREADS   8
 
#define ITERATIONS_PER_THREAD   500
 

Functions

void bare_helgrind_handler (int a, int b)
 A simple C callback function; its only purpose is to be a valid call target.
 
void * bare_thread_worker (void *arg)
 The main function executed by each worker thread.
 
int main (void)
 

Detailed Description

A "barebones" thread-safety test with no testing framework dependency.

Copyright (c) 2025 Sanko Robinson

This source code is dual-licensed under the Artistic License 2.0 or the MIT License. You may choose to use this code under the terms of either license.

SPDX-License-Identifier: (Artistic-2.0 OR MIT)

The documentation blocks within this file are licensed under the Creative Commons Attribution 4.0 International License (CC BY 4.0).

SPDX-License-Identifier: CC-BY-4.0

This test is designed to be the ultimate proof of thread safety for the infix library. It is intended to be compiled as a standalone executable and run under Valgrind's Helgrind tool.

By removing the dependency on the double_tap.h testing framework (which is not designed for this kind of stress test and can create noisy, misleading reports), we ensure that the only shared code being stressed is the infix library itself. This provides a clean, unambiguous result.

The test's success is determined by two conditions:

  1. The program must exit with code 0.
  2. Valgrind/Helgrind must report ZERO errors.

Macro Definition Documentation

◆ ITERATIONS_PER_THREAD

#define ITERATIONS_PER_THREAD   500

◆ NUM_THREADS

#define NUM_THREADS   8

Function Documentation

◆ bare_helgrind_handler()

void bare_helgrind_handler ( int  a,
int  b 
)

A simple C callback function; its only purpose is to be a valid call target.

◆ bare_thread_worker()

void * bare_thread_worker ( void *  arg)

The main function executed by each worker thread.

Creates, uses, and destroys a reverse trampoline in a tight loop.

Returns
Returns a status code (0 for success, 1 for failure) cast to a void pointer.

◆ main()

int main ( void  )