文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Create Two Threads and End with ESC

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);
    }
}
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载