Created
October 21, 2022 23:47
-
-
Save brenns10/cc57bcb4154759c6edba5e803c8e87f7 to your computer and use it in GitHub Desktop.
stupid core dump
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Sample multi-threaded application for core dump. | |
* gcc -pthread -g -O0 -o coredump coredump.c | |
*/ | |
#define _GNU_SOURCE | |
#include <stdlib.h> | |
#include <stdio.h> | |
#include <pthread.h> | |
#include <sys/types.h> | |
#include <unistd.h> | |
#define DECLARE(name) \ | |
void name(int arg_a, int arg_b, int arg_c, pid_t tid); | |
#define DEFINE(name, call_next) \ | |
void name(int arg_a, int arg_b, int arg_c, pid_t tid) \ | |
{ \ | |
volatile int var_one = 0; \ | |
volatile int var_two = 0; \ | |
volatile int var_three = 0; \ | |
\ | |
while (var_one < arg_a) { \ | |
var_one += 1; \ | |
var_two += 1; \ | |
var_three += 1; \ | |
call_next(arg_a, arg_b, arg_c, tid); \ | |
} \ | |
printf("%d %d %d\n", var_one, var_two, var_three); \ | |
} | |
#define nelem(arr) (sizeof(arr) / sizeof((arr)[0])) | |
DECLARE(foo); | |
DECLARE(bar); | |
DECLARE(baz); | |
DECLARE(last); | |
DEFINE(foo, bar); | |
DEFINE(bar, baz); | |
DEFINE(baz, last); | |
void last(int arg_a, int arg_b, int arg_c, pid_t tid) | |
{ | |
sleep(20); | |
} | |
void *thread_run(void *arg) | |
{ | |
pid_t tid = gettid(); | |
printf("%u\n", tid); | |
foo(123, 456, 789, tid); | |
return NULL; | |
} | |
int main(int argc, char **argv) | |
{ | |
pthread_t threads[16]; | |
for (int i = 0; i < nelem(threads); i++) { | |
pthread_create(&threads[i], NULL, thread_run, NULL); | |
} | |
sleep(1); | |
abort(); | |
for (int i = 0; i < nelem(threads); i++) { | |
pthread_join(threads[i], NULL); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment