声明同这篇文章,以下是代码
#include <cmnheader.h>
void *theThread(void *param)
{
printf("Thread: Entered\n");
while (1)
{
printf("Thread: Looping or long running request\n");
pthread_testcancel();
Sleep(1);
}
return NULL;
}
int main(int argc, char **argv)
{
pthread_t thread;
int rc = 0;
void *status;
printf("Enter Testcase - %s\n", argv[0]);
printf("Create/start a thread\n");
rc = pthread_create(&thread, NULL, theThread, NULL);
checkResults("pthread_create()\n", rc);
printf("Wait a bit until we 'realize' the thread needs to be canceled\n");
Sleep(3);
rc = pthread_cancel(thread);
checkResults("pthread_cancel()\n", rc);
printf("Wait for the thread to complete, and release its resources\n");
rc = pthread_join(thread