35 lines
625 B
C
35 lines
625 B
C
#include <pthread.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
|
|
#define SIZE 32768
|
|
|
|
pthread_t child_thread;
|
|
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
int table[SIZE];
|
|
|
|
int cmp(const void* a1, const void* a2){
|
|
return *((int*)a2) - *((int*)a1);
|
|
}
|
|
|
|
void* child(void* args){
|
|
pthread_mutex_lock(&mutex);
|
|
for (int i = 0; i < SIZE; ++i) {
|
|
table[i] = rand();
|
|
}
|
|
pthread_mutex_unlock(&mutex);
|
|
sleep(1);
|
|
pthread_mutex_lock(&mutex);
|
|
return NULL;
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
pthread_create(&child_thread, NULL, child, NULL);
|
|
|
|
pthread_mutex_lock(&mutex);
|
|
qsort(table, SIZE, sizeof(int), cmp);
|
|
pthread_mutex_unlock(&mutex);
|
|
}
|