Skip to content

Instantly share code, notes, and snippets.

View BarbotAnder's full-sized avatar

Ander Barbot BarbotAnder

View GitHub Profile
#include "lab.h"
#include <stdio.h>
#include <stdlib.h>
// Authored by: Myself
// Thread-safe: Not Thread-safe (allocates shared structures without synchronization)
list_t *list_init(void (*destroy_data)(void *), int (*compare_to)(const void *, const void *)) {
list_t *list = (list_t *)malloc(sizeof(list_t)); // external function: malloc (thread-safe)
if (list == NULL) {
return NULL;
@BarbotAnder
BarbotAnder / logger.c
Last active April 5, 2025 03:45
thread safety analysis of a logger. partially generated using LLM
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define NUM_THREADS 4
pthread_mutex_t log_mutex = PTHREAD_MUTEX_INITIALIZER; // EXT(ernal function): mutex to protect output stream
// Authored by: Myself