重複の可能性:
pthreadでスレッドを強制終了します
ここでは、スレッドの起動を含むソースコードの後、しばらくしてそれを強制終了したいと思います。どうやってするの ?スレッド機能を変更せずに
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
pthread_t test_thread;
void *thread_test_run (void *v) // I must not modify this function
{
int i=1;
while(1)
{
printf("into thread %d\r\n",i);
i++;
sleep(1);
}
return NULL
}
int main()
{
pthread_create(&test_thread, NULL, &thread_test_run, NULL);
sleep (20);
// Kill the thread here. How to do it?
// other function are called here...
return 0;
}