Files
RedBear-OS/recipes/tests/pthread/thread_fork.c
T
vasilito b9874d0941 feat: USB storage read/write proof + full Red Bear OS tree sync
Add redbear-usb-storage-check in-guest binary that validates USB mass
storage read and write I/O: discovers /scheme/disk/ devices, writes a
test pattern to sector 2048, reads it back, verifies match, restores
original content. Updates test-usb-storage-qemu.sh with write-proof
verification step.

Includes all accumulated Red Bear OS work: kernel patches, relibc
patches, driver infrastructure, DRM/GPU, KDE recipes, firmware,
validation tooling, build system hardening, and documentation.
2026-05-03 23:03:24 +01:00

52 lines
957 B
C

/// test fork inside thread
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <sys/wait.h>
#include "test_helpers.h"
#define NUM_THREADS 4
#define ITERATIONS 3
void* thread_func(void* arg) {
long tid = (long)arg;
for (int i = 0; i < ITERATIONS; i++) {
printf("thread %ld loop %i\n", tid, i);
pid_t pid = fork();
ERROR_IF(fork, pid, < 0);
if (pid == 0) {
_exit(0);
} else {
waitpid(pid, NULL, 0);
}
usleep(1000);
}
return NULL;
}
int main() {
pthread_t threads[NUM_THREADS];
int status;
for (long i = 0; i < NUM_THREADS; i++) {
status = pthread_create(&threads[i], NULL, thread_func, (void*)i);
ERROR_IF(pthread_create, status, != 0);
}
printf("joining threads\n");
for (int i = 0; i < NUM_THREADS; i++) {
pthread_join(threads[i], NULL);
}
return 0;
}