mir icon indicating copy to clipboard operation
mir copied to clipboard

Please implement _Thread_local

Open andy-hanson opened this issue 1 year ago • 1 comments

#include <assert.h>
#include <pthread.h>

static _Thread_local int x;

void* thread_fn(void* arg) {
	x = 1;
	return NULL;
}

int main(void) {
	x = 0;

	pthread_t thread;
	int err = pthread_create(&thread, NULL, thread_fn, NULL);
	assert(err == 0);
	void* ret;
	err = pthread_join(thread, &ret);
	assert(err == 0);
	assert(ret == NULL);

	assert(x == 0);
	return 0;
}

This program works with GCC/clang but breaks with c2m (at assert(x == 0);). It appears that _Thread_local is not implemented.

andy-hanson avatar Mar 17 '24 02:03 andy-hanson

the feature relies on libc and libpthread to co-operate, which is hard for MIR to do.

iacore avatar Mar 17 '24 17:03 iacore