Here is a simple sample for running two threads in a process, and each one prints a message until you key in ESC and ENTER.
May you tell me how to just key in ESC without ENTER to exit main()? Please send the answer to prinz.tigris@gmail.com. Thank you first.
#include
#include
void* a_thread()
{
while (1) {
printf("This is a thread.\n");
sleep(1);
}
return;
}
void* b_thread()
{
while (1) {
printf("This is b thread.\n");
sleep(1);
}
return;
}
int main()
{
pthread_t a_tid;
pthread_t b_tid;
pthread_create(&a_tid, NULL, a_thread, NULL);
pthread_create(&b_tid, NULL, b_thread, NULL);
while ( 0x1b != getc(stdin)) {
printf("I am the main thread, and Enter ESC to quit.\n");
sleep(1);
}
}
阅读(829) | 评论(0) | 转发(0) |