Chinaunix首页 | 论坛 | 博客
  • 博客访问: 67103
  • 博文数量: 22
  • 博客积分: 1406
  • 博客等级: 上尉
  • 技术积分: 190
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-13 13:18
文章分类

全部博文(22)

文章存档

2011年(1)

2010年(21)

我的朋友

分类: C/C++

2010-03-06 17:01:03

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);
    }
}
阅读(816) | 评论(0) | 转发(0) |
0

上一篇:Components of C Program

下一篇:Process and Thread

给主人留下些什么吧!~~