Create Two Threads and End with ESC
时间:2010-03-06 来源:victorgreat
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 [email protected]. Thank you first.
#include <stdio.h>
#include <pthread.h>
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);
}
}
May you tell me how to just key in ESC without ENTER to exit main()? Please send the answer to [email protected]. Thank you first.
#include <stdio.h>
#include <pthread.h>
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);
}
}
相关阅读 更多 +