mirror of
https://github.com/Pithikos/C-Thread-Pool
synced 2024-11-22 05:31:18 +03:00
External bugs added
This commit is contained in:
parent
11a5544702
commit
e89ab31e42
36
tests/ext_bugs/memleak.c
Normal file
36
tests/ext_bugs/memleak.c
Normal file
@ -0,0 +1,36 @@
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
|
||||
volatile int threads_keepalive = 1;
|
||||
|
||||
void* thread_do(void *arg){
|
||||
while(threads_keepalive)
|
||||
sleep(1);
|
||||
pthread_exit(NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
int main(void){
|
||||
|
||||
/* Make threads */
|
||||
pthread_t* threads;
|
||||
threads = malloc(2 * sizeof(pthread_t));
|
||||
pthread_create(&threads[0], NULL, &thread_do, NULL);
|
||||
pthread_create(&threads[1], NULL, &thread_do, NULL);
|
||||
pthread_detach(threads[0]);
|
||||
pthread_detach(threads[1]);
|
||||
sleep(1); // MAKING SURE THREADS HAVE INITIALIZED
|
||||
|
||||
/* Kill threads */
|
||||
threads_keepalive = 0;
|
||||
sleep(3); // MAKING SURE THREADS HAVE UNBLOCKED
|
||||
pthread_join(threads[0], NULL);
|
||||
pthread_join(threads[1], NULL);
|
||||
free(threads);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user