[Llvm-bgq-discuss] C11 threads.h

Hal Finkel hfinkel at anl.gov
Mon Apr 13 12:39:04 CDT 2015


Hi again,

The glibc on the BG/Q does not support the C11 threads.h header (and likely never will). I've imported into the bgclang project a simple implementation of the C11 threads.h header from the Mesa project (which implements the C11 thread functions using pthreads). If you use bgclang you'll be able to use the threads.h header, you just need to remember to link with the pthreads library (using the command-line flag -pthread will do it).

For example:

$ /soft/compilers/bgclang/r234750-20150413/wbin/bgclang -o c11_threads_test c11_threads_test.c -pthread
$ cat c11_threads_test.c # which is this: https://github.com/jtsiomb/c11threads/blob/master/test.c
#include <stdio.h>
#include <threads.h>

void tfunc(void *arg);

int main(void)
{
	int i;
	thrd_t threads[4];

	for(i=0; i<4; i++) {
		thrd_create(threads + i, tfunc, (void*)(long)i);
	}

	for(i=0; i<4; i++) {
		thrd_join(threads[i], 0);
	}

	return 0;
}

void tfunc(void *arg)
{
	int num = (long)arg;
	xtime dur;

	printf("hello from thread %d\n", num);

	dur.sec = 4;
	dur.nsec = 0;
	thrd_sleep(&dur);

	printf("thread %d done\n", num);
}

 -Hal

-- 
Hal Finkel
Assistant Computational Scientist
Leadership Computing Facility
Argonne National Laboratory


More information about the llvm-bgq-discuss mailing list