我对退出 while 循环有疑问。我正在编写代码,其中创建了两个线程,它们打印字符串,而 main() 部分必须每 500 毫秒打印一次点 (".")。你能帮我在第二个线程终止后如何退出while循环,以便在输出中得到类似的东西:...Hello...World....THE END
感谢您的帮助。
int main()
{
int mls = 0.5 ;
pthread_t thread1;
pthread_t thread2;
struktura param1 = { "Hello", 2};
struktura param2 = { "World", 4};
pthread_create( &thread1, NULL, thread, ¶m1);
pthread_create( &thread2, NULL, thread, ¶m2);
while(1)
{
printf(".");
fflush(stdout);
sleep(mls);
}
pthread_join(thread1, NULL);
pthread_join(thread2, NULL);
printf("THE END\n");
return 0;
}