You need join every thread you created, so you can't reuse the same pthread_t
variable, and 20000 threads may be too many.
#include <pthread.h>
#include <stdio.h>
int S = 0;
pthread_t t[201];
pthread_mutex_t lock=PTHREAD_MUTEX_INITIALIZER;
suma(){
pthread_mutex_lock(&lock);
S++;
pthread_mutex_unlock(&lock);
}
int main(){
int i;
for(i=1;i<=200;i++)
pthread_create(&t[i],NULL,suma,NULL);
for(i=1;i<=200;i++)
pthread_join(t[i],NULL);
printf("%d",S);
}