⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 example01.lc

📁 unix网络编程第一卷socket编程书上的全部源代码
💻 LC
字号:
#include    "unpthread.h"##  1 ##src/threads/example01.c###define NLOOP 5000##  2 ##src/threads/example01.c##int     counter;                /* this is incremented by the threads */##  3 ##src/threads/example01.c##void   *doit(void *);##  4 ##src/threads/example01.c##int##  5 ##src/threads/example01.c##main(int argc, char **argv)##  6 ##src/threads/example01.c##{##  7 ##src/threads/example01.c##    pthread_t tidA, tidB;##  8 ##src/threads/example01.c##    Pthread_create(&tidA, NULL, &doit, NULL);##  9 ##src/threads/example01.c##    Pthread_create(&tidB, NULL, &doit, NULL);## 10 ##src/threads/example01.c##    /* 4wait for both threads to terminate */## 11 ##src/threads/example01.c##    Pthread_join(tidA, NULL);## 12 ##src/threads/example01.c##    Pthread_join(tidB, NULL);## 13 ##src/threads/example01.c##    exit(0);## 14 ##src/threads/example01.c##}## 15 ##src/threads/example01.c##void   *## 16 ##src/threads/example01.c##doit(void *vptr)## 17 ##src/threads/example01.c##{## 18 ##src/threads/example01.c##    int     i, val;## 19 ##src/threads/example01.c##    /* ## 20 ##src/threads/example01.c##     * Each thread fetches, prints, and increments the counter NLOOP times.## 21 ##src/threads/example01.c##     * The value of the counter should increase monotonically.## 22 ##src/threads/example01.c##     */## 23 ##src/threads/example01.c##    for (i = 0; i < NLOOP; i++) {## 24 ##src/threads/example01.c##        val = counter;## 25 ##src/threads/example01.c##        printf("%d: %d\n", pthread_self(), val + 1);## 26 ##src/threads/example01.c##        counter = val + 1;## 27 ##src/threads/example01.c##    }## 28 ##src/threads/example01.c##    return (NULL);## 29 ##src/threads/example01.c##}## 30 ##src/threads/example01.c##

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -