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

A cross-platform test for thread-safety issues using Valgrind's Helgrind tool or other thread sanitizers. More...

#include "common/double_tap.h"
#include "common/infix_config.h"
#include <infix/infix.h>
#include <stdbool.h>
#include <pthread.h>
#include <stdint.h>
Include dependency graph for 820_threading_helgrind.c:

Macros

#define DBLTAP_IMPLEMENTATION
 
#define NUM_THREADS   8
 
#define ITERATIONS_PER_THREAD   500
 

Functions

void helgrind_test_handler (int a, int b)
 
void * helgrind_thread_worker (void *arg)
 
 subtest ("Thread-safety stress test")
 

Variables

 TEST
 

Detailed Description

A cross-platform test for thread-safety issues using Valgrind's Helgrind tool or other thread sanitizers.

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 run specifically under thread analysis tools. It creates multiple threads that concurrently generate, use, and destroy FFI reverse trampolines (callbacks). The tool will analyze the execution for potential data races and other synchronization errors in the underlying library code.

This version of the test is structured to be free of data races in the test code itself. All reporting is done by the main thread after all worker threads have completed. Therefore, a successful run should produce ZERO errors from the analysis tool. Any reported error indicates a genuine thread-safety bug within the infix library.

Macro Definition Documentation

◆ DBLTAP_IMPLEMENTATION

#define DBLTAP_IMPLEMENTATION

◆ ITERATIONS_PER_THREAD

#define ITERATIONS_PER_THREAD   500

◆ NUM_THREADS

#define NUM_THREADS   8

Function Documentation

◆ helgrind_test_handler()

void helgrind_test_handler ( int  a,
int  b 
)

◆ helgrind_thread_worker()

void * helgrind_thread_worker ( void *  arg)

◆ subtest()

subtest ( "Thread-safety stress test"  )

Variable Documentation

◆ TEST

TEST
Initial value:
{
plan(1)
#define plan(count)
Definition double_tap.h:132