May I ask questions about threads under Linux

zhaozj2021-02-16  57

Please take a look at the following small programs.

#include #include

Void * threadtask; "VOID * ARG);

int main (void) {int status; char ch; pthread_t MyThread; void * result; status = pthread_create (& MyThread, NULL, ThreadTask, NULL); if (status = 0!) printf ( "thread create error / n"); Sleep (3); pthread_cancel (mythread); Printf ("come to here / n"); pthread_join (mythread, & result); Printf ("exit ........... / n"); return; } void * threadtask (void * arg)

{INT A; while (1) {a = 1; SLEEP (1);}}

It only runs to the screen print output "come to here", it will die there. . . .

What is going on? ? ? ? ? ?

Thank you

转载请注明原文地址:https://www.9cbs.com/read-20554.html

New Post(0)