hivert is right, C and C++ are different languages.
Try this:
#include<pthread.h>
#include<stdio.h>
#include<tbb/atomic.h>
#define NUM_OF_THREADS 16
tbb::atomic<int> counter;
void *simpleCounter(void *threadId)
{
int i;
for(i=0;i<256;i++)
{
counter.fetch_and_add(1);
}
printf("T%ld \t Counter %d\n", (long) threadId, (int)counter);
pthread_exit(NULL);
}
int main(int argc, char *argv[])
{
counter=0;
pthread_t threadArray[NUM_OF_THREADS];
long i;
for(i=0;i<NUM_OF_THREADS;i++)
{
pthread_create(&threadArray[i], NULL, simpleCounter, (void *)i);
}
for(i=0;i<NUM_OF_THREADS;i++)
pthread_join(threadArray[i], nullptr);
}
Save it with .cpp extension (not required with g++). I modified the missing namespace tbb::atomic and I also included a join in the end, to wait all threads to finish before quitting main. It should compile now. Add -std=c++11 as a compiler option, or change nullptr to NULL.