国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

第三章 Linux多線程開發(fā) 線程取消 屬性 同步 互斥鎖 死鎖 讀寫鎖 生產(chǎn)者消費者 信號量

這篇具有很好參考價值的文章主要介紹了第三章 Linux多線程開發(fā) 線程取消 屬性 同步 互斥鎖 死鎖 讀寫鎖 生產(chǎn)者消費者 信號量。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

第三章 Linux多線程開發(fā) 線程取消 屬性 同步 互斥鎖 死鎖 讀寫鎖 生產(chǎn)者消費者 信號量,webserver,linux,運維,服務(wù)器

線程取消:

/*
    #include <pthread.h>
    int pthread_cancel(pthread_t thread);
        - 功能:取消線程(讓線程終止)
            取消某個線程,可以終止某個線程的運行,
            但是并不是立馬終止,而是當子線程執(zhí)行到一個取消點,線程才會終止。
            取消點:系統(tǒng)規(guī)定好的一些系統(tǒng)調(diào)用,我們可以粗略的理解為從用戶區(qū)到內(nèi)核區(qū)的切換,這個位置稱之為取消點。
*/

#include <stdio.h>
#include <pthread.h>
#include <string.h>
#include <unistd.h>

void * callback(void * arg) {
    printf("chid thread id : %ld\n", pthread_self());
    for(int i = 0; i < 5; i++) {
        printf("child : %d\n", i);
    }
    return NULL;
}

int main() {
    
    // 創(chuàng)建一個子線程
    pthread_t tid;

    int ret = pthread_create(&tid, NULL, callback, NULL);
    if(ret != 0) {
        char * errstr = strerror(ret);
        printf("error1 : %s\n", errstr);
    }

    // 取消線程 不是立刻取消的  
    pthread_cancel(tid);

    for(int i = 0; i < 5; i++) {
        printf("%d\n", i);
    }

    // 輸出主線程和子線程的id
    printf("tid : %ld, main thread id : %ld\n", tid, pthread_self());

    
    pthread_exit(NULL);

    return 0;
}

線程屬性

/*
    int pthread_attr_init(pthread_attr_t *attr);
        - 初始化線程屬性變量

    int pthread_attr_destroy(pthread_attr_t *attr);
        - 釋放線程屬性的資源

    int pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate);
        - 獲取線程分離的狀態(tài)屬性

    int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate);
        - 設(shè)置線程分離的狀態(tài)屬性
*/     

#include <stdio.h>
#include <pthread.h>
#include <string.h>
#include <unistd.h>

void * callback(void * arg) {
    printf("chid thread id : %ld\n", pthread_self());
    return NULL;
}

int main() {

    // 創(chuàng)建一個線程屬性變量
    pthread_attr_t attr;
    // 初始化屬性變量
    pthread_attr_init(&attr);

    // 設(shè)置屬性
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);

    // 創(chuàng)建一個子線程
    pthread_t tid;

    int ret = pthread_create(&tid, &attr, callback, NULL);
    if(ret != 0) {
        char * errstr = strerror(ret);
        printf("error1 : %s\n", errstr);
    }

    // 獲取線程的棧的大小
    size_t size;
    pthread_attr_getstacksize(&attr, &size);
    printf("thread stack size : %ld\n", size);

    // 輸出主線程和子線程的id
    printf("tid : %ld, main thread id : %ld\n", tid, pthread_self());

    // 釋放線程屬性資源
    pthread_attr_destroy(&attr);

    pthread_exit(NULL);

    return 0;
}

線程同步

第三章 Linux多線程開發(fā) 線程取消 屬性 同步 互斥鎖 死鎖 讀寫鎖 生產(chǎn)者消費者 信號量,webserver,linux,運維,服務(wù)器
第三章 Linux多線程開發(fā) 線程取消 屬性 同步 互斥鎖 死鎖 讀寫鎖 生產(chǎn)者消費者 信號量,webserver,linux,運維,服務(wù)器
第三章 Linux多線程開發(fā) 線程取消 屬性 同步 互斥鎖 死鎖 讀寫鎖 生產(chǎn)者消費者 信號量,webserver,linux,運維,服務(wù)器
第三章 Linux多線程開發(fā) 線程取消 屬性 同步 互斥鎖 死鎖 讀寫鎖 生產(chǎn)者消費者 信號量,webserver,linux,運維,服務(wù)器
第三章 Linux多線程開發(fā) 線程取消 屬性 同步 互斥鎖 死鎖 讀寫鎖 生產(chǎn)者消費者 信號量,webserver,linux,運維,服務(wù)器
第三章 Linux多線程開發(fā) 線程取消 屬性 同步 互斥鎖 死鎖 讀寫鎖 生產(chǎn)者消費者 信號量,webserver,linux,運維,服務(wù)器
第三章 Linux多線程開發(fā) 線程取消 屬性 同步 互斥鎖 死鎖 讀寫鎖 生產(chǎn)者消費者 信號量,webserver,linux,運維,服務(wù)器
第三章 Linux多線程開發(fā) 線程取消 屬性 同步 互斥鎖 死鎖 讀寫鎖 生產(chǎn)者消費者 信號量,webserver,linux,運維,服務(wù)器

第三章 Linux多線程開發(fā) 線程取消 屬性 同步 互斥鎖 死鎖 讀寫鎖 生產(chǎn)者消費者 信號量,webserver,linux,運維,服務(wù)器
第三章 Linux多線程開發(fā) 線程取消 屬性 同步 互斥鎖 死鎖 讀寫鎖 生產(chǎn)者消費者 信號量,webserver,linux,運維,服務(wù)器

多線程實現(xiàn)賣票:

selltickets.c(沒有加鎖的情況) 線程同步

/*
    使用多線程實現(xiàn)買票的案例。
    有3個窗口,一共是100張票。
*/

#include <stdio.h>
#include <pthread.h>
#include <unistd.h>

// 全局變量,所有的線程都共享這一份資源。
int tickets = 100;

void * sellticket(void * arg) {
    // 賣票
    while(tickets > 0) {
        usleep(6000);
        printf("%ld 正在賣第 %d 張門票\n", pthread_self(), tickets);
        tickets--;
    }
    return NULL;
}

int main() {

    // 創(chuàng)建3個子線程
    pthread_t tid1, tid2, tid3;
    pthread_create(&tid1, NULL, sellticket, NULL);
    pthread_create(&tid2, NULL, sellticket, NULL);
    pthread_create(&tid3, NULL, sellticket, NULL);

    // 回收子線程的資源,阻塞
    pthread_join(tid1, NULL);
    pthread_join(tid2, NULL);
    pthread_join(tid3, NULL);

    // 設(shè)置線程分離。
    // pthread_detach(tid1);
    // pthread_detach(tid2);
    // pthread_detach(tid3);

    pthread_exit(NULL); // 退出主線程

    return 0;
}

互斥鎖 mutex.c

/*
    互斥量的類型 pthread_mutex_t
    int pthread_mutex_init(pthread_mutex_t *restrict mutex, const pthread_mutexattr_t *restrict attr);
        - 初始化互斥量
        - 參數(shù) :
            - mutex : 需要初始化的互斥量變量
            - attr : 互斥量相關(guān)的屬性,NULL
        - restrict : C語言的修飾符,被修飾的指針,不能由另外的一個指針進行操作。
            pthread_mutex_t *restrict mutex = xxx;
            pthread_mutex_t * mutex1 = mutex;

    int pthread_mutex_destroy(pthread_mutex_t *mutex);
        - 釋放互斥量的資源

    int pthread_mutex_lock(pthread_mutex_t *mutex);
        - 加鎖,阻塞的,如果有一個線程加鎖了,那么其他的線程只能阻塞等待

    int pthread_mutex_trylock(pthread_mutex_t *mutex);
        - 嘗試加鎖,如果加鎖失敗,不會阻塞,會直接返回。

    int pthread_mutex_unlock(pthread_mutex_t *mutex);
        - 解鎖
*/
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>

// 全局變量,所有的線程都共享這一份資源。
int tickets = 1000;

// 創(chuàng)建一個互斥量
pthread_mutex_t mutex;

void * sellticket(void * arg) {  //該函數(shù)是一個線程函數(shù),接收一個void*類型的參數(shù),并返回一個void*類型的指針。

    // 賣票
    while(1) {

        // 加鎖
        pthread_mutex_lock(&mutex);		//通過調(diào)用pthread_mutex_lock函數(shù)來獲取互斥鎖。&mutex是互斥鎖的地址,用于鎖住臨界區(qū),保證線程安全

        if(tickets > 0) {
            usleep(6000); 				//通過調(diào)用usleep函數(shù)來使線程暫停6000微秒,相當于6毫秒,模擬賣票的過程。
            printf("%ld 正在賣第 %d 張門票\n", pthread_self(), tickets);		//長整型(long類型)
            tickets--;
        }else {
            // 解鎖
            pthread_mutex_unlock(&mutex);
            break;
        }

        // 解鎖
        pthread_mutex_unlock(&mutex);
    }

    

    return NULL;
}

int main() {

    // 初始化互斥量
    pthread_mutex_init(&mutex, NULL);

    // 創(chuàng)建3個子線程
    pthread_t tid1, tid2, tid3;
    pthread_create(&tid1, NULL, sellticket, NULL);
    pthread_create(&tid2, NULL, sellticket, NULL);
    pthread_create(&tid3, NULL, sellticket, NULL);

    // 回收子線程的資源,阻塞
    pthread_join(tid1, NULL);
    pthread_join(tid2, NULL);
    pthread_join(tid3, NULL);

    pthread_exit(NULL); // 退出主線程

    // 釋放互斥量資源
    pthread_mutex_destroy(&mutex);

    return 0;
}

第三章 Linux多線程開發(fā) 線程取消 屬性 同步 互斥鎖 死鎖 讀寫鎖 生產(chǎn)者消費者 信號量,webserver,linux,運維,服務(wù)器
第三章 Linux多線程開發(fā) 線程取消 屬性 同步 互斥鎖 死鎖 讀寫鎖 生產(chǎn)者消費者 信號量,webserver,linux,運維,服務(wù)器

死鎖:deadlock1.c

第三章 Linux多線程開發(fā) 線程取消 屬性 同步 互斥鎖 死鎖 讀寫鎖 生產(chǎn)者消費者 信號量,webserver,linux,運維,服務(wù)器

#include <stdio.h>
#include <pthread.h>
#include <unistd.h>

// 創(chuàng)建2個互斥量
pthread_mutex_t mutex1, mutex2;

void * workA(void * arg) {

    pthread_mutex_lock(&mutex1);
    sleep(1);
    pthread_mutex_lock(&mutex2);

    printf("workA....\n");

    pthread_mutex_unlock(&mutex2);
    pthread_mutex_unlock(&mutex1);
    return NULL;
}


void * workB(void * arg) {
    pthread_mutex_lock(&mutex2);
    sleep(1);
    pthread_mutex_lock(&mutex1);

    printf("workB....\n");

    pthread_mutex_unlock(&mutex1);
    pthread_mutex_unlock(&mutex2);

    return NULL;
}

int main() {

    // 初始化互斥量
    pthread_mutex_init(&mutex1, NULL);
    pthread_mutex_init(&mutex2, NULL);

    // 創(chuàng)建2個子線程
    pthread_t tid1, tid2;
    pthread_create(&tid1, NULL, workA, NULL);
    pthread_create(&tid2, NULL, workB, NULL);

    // 回收子線程資源
    pthread_join(tid1, NULL);
    pthread_join(tid2, NULL);

    // 釋放互斥量資源
    pthread_mutex_destroy(&mutex1);
    pthread_mutex_destroy(&mutex2);

    return 0;
}

讀寫鎖

第三章 Linux多線程開發(fā) 線程取消 屬性 同步 互斥鎖 死鎖 讀寫鎖 生產(chǎn)者消費者 信號量,webserver,linux,運維,服務(wù)器
第三章 Linux多線程開發(fā) 線程取消 屬性 同步 互斥鎖 死鎖 讀寫鎖 生產(chǎn)者消費者 信號量,webserver,linux,運維,服務(wù)器

/*
    讀寫鎖的類型 pthread_rwlock_t
    int pthread_rwlock_init(pthread_rwlock_t *restrict rwlock, const pthread_rwlockattr_t *restrict attr);
    int pthread_rwlock_destroy(pthread_rwlock_t *rwlock);
    int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock);
    int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock);
    int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock);
    int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock);
    int pthread_rwlock_unlock(pthread_rwlock_t *rwlock);

    案例:8個線程操作同一個全局變量。
    3個線程不定時寫這個全局變量,5個線程不定時的讀這個全局變量
*/

#include <stdio.h>
#include <pthread.h>
#include <unistd.h>

// 創(chuàng)建一個共享數(shù)據(jù)
int num = 1;
// pthread_mutex_t mutex;
pthread_rwlock_t rwlock;

void * writeNum(void * arg) {

    while(1) {
        pthread_rwlock_wrlock(&rwlock);
        num++;
        printf("++write, tid : %ld, num : %d\n", pthread_self(), num);  //pthread_self()獲取當前線程的線程ID
        pthread_rwlock_unlock(&rwlock);
        usleep(100);
    }

    return NULL;
}

void * readNum(void * arg) {

    while(1) {
        pthread_rwlock_rdlock(&rwlock);
        printf("===read, tid : %ld, num : %d\n", pthread_self(), num);
        pthread_rwlock_unlock(&rwlock);
        usleep(100);
    }

    return NULL;
}

int main() {

   pthread_rwlock_init(&rwlock, NULL);

    // 創(chuàng)建3個寫線程,5個讀線程
    pthread_t wtids[3], rtids[5];
    for(int i = 0; i < 3; i++) {
        pthread_create(&wtids[i], NULL, writeNum, NULL);
    }

    for(int i = 0; i < 5; i++) {
        pthread_create(&rtids[i], NULL, readNum, NULL);
    }

    // 設(shè)置線程分離
    for(int i = 0; i < 3; i++) {
       pthread_detach(wtids[i]);
    }

    for(int i = 0; i < 5; i++) {
         pthread_detach(rtids[i]);
    }

    pthread_exit(NULL);

    pthread_rwlock_destroy(&rwlock);

    return 0;
}

生產(chǎn)者與消費者模型

第三章 Linux多線程開發(fā) 線程取消 屬性 同步 互斥鎖 死鎖 讀寫鎖 生產(chǎn)者消費者 信號量,webserver,linux,運維,服務(wù)器文章來源地址http://www.zghlxwxcb.cn/news/detail-697182.html

/*
    生產(chǎn)者消費者模型(粗略的版本)
*/
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>

// 創(chuàng)建一個互斥量
pthread_mutex_t mutex;

struct Node{
    int num;
    struct Node *next;
};

// 頭結(jié)點
struct Node * head = NULL;

void * producer(void * arg) {

    // 不斷的創(chuàng)建新的節(jié)點,添加到鏈表中
    while(1) {
        pthread_mutex_lock(&mutex);
        struct Node * newNode = (struct Node *)malloc(sizeof(struct Node));
        newNode->next = head;
        head = newNode;
        newNode->num = rand() % 1000;
        printf("add node, num : %d, tid : %ld\n", newNode->num, pthread_self());
        pthread_mutex_unlock(&mutex);
        usleep(100);
    }

    return NULL;
}

void * customer(void * arg) {

    while(1) {
        pthread_mutex_lock(&mutex);
        // 保存頭結(jié)點的指針
        struct Node * tmp = head;

        // 判斷是否有數(shù)據(jù)
        if(head != NULL) {
            // 有數(shù)據(jù)
            head = head->next;
            printf("del node, num : %d, tid : %ld\n", tmp->num, pthread_self());
            free(tmp);
            pthread_mutex_unlock(&mutex);
            usleep(100);
        } else {
            // 沒有數(shù)據(jù)
            pthread_mutex_unlock(&mutex);
        }
    }
    return  NULL;
}

int main() {

    pthread_mutex_init(&mutex, NULL);

    // 創(chuàng)建5個生產(chǎn)者線程,和5個消費者線程
    pthread_t ptids[5], ctids[5];

    for(int i = 0; i < 5; i++) {
        pthread_create(&ptids[i], NULL, producer, NULL);
        pthread_create(&ctids[i], NULL, customer, NULL);
    }

    for(int i = 0; i < 5; i++) {
        pthread_detach(ptids[i]);
        pthread_detach(ctids[i]);
    }

    while(1) {
        sleep(10);
    }

    pthread_mutex_destroy(&mutex);

    pthread_exit(NULL);

    return 0;
}

條件變量

/*
    條件變量的類型 pthread_cond_t
    int pthread_cond_init(pthread_cond_t *restrict cond, const pthread_condattr_t *restrict attr);
    int pthread_cond_destroy(pthread_cond_t *cond);
    int pthread_cond_wait(pthread_cond_t *restrict cond, pthread_mutex_t *restrict mutex);
        - 等待,調(diào)用了該函數(shù),線程會阻塞。
    int pthread_cond_timedwait(pthread_cond_t *restrict cond, pthread_mutex_t *restrict mutex, const struct timespec *restrict abstime);
        - 等待多長時間,調(diào)用了這個函數(shù),線程會阻塞,直到指定的時間結(jié)束。
    int pthread_cond_signal(pthread_cond_t *cond);
        - 喚醒一個或者多個等待的線程
    int pthread_cond_broadcast(pthread_cond_t *cond);
        - 喚醒所有的等待的線程
*/
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>

// 創(chuàng)建一個互斥量
pthread_mutex_t mutex;
// 創(chuàng)建條件變量
pthread_cond_t cond;

struct Node{
    int num;
    struct Node *next;
};

// 頭結(jié)點
struct Node * head = NULL;

void * producer(void * arg) {

    // 不斷的創(chuàng)建新的節(jié)點,添加到鏈表中
    while(1) {
        pthread_mutex_lock(&mutex);
        struct Node * newNode = (struct Node *)malloc(sizeof(struct Node));
        newNode->next = head;
        head = newNode;
        newNode->num = rand() % 1000;
        printf("add node, num : %d, tid : %ld\n", newNode->num, pthread_self());
        
        // 只要生產(chǎn)了一個,就通知消費者消費
        pthread_cond_signal(&cond);

        pthread_mutex_unlock(&mutex);
        usleep(100);
    }

    return NULL;
}

void * customer(void * arg) {

    while(1) {
        pthread_mutex_lock(&mutex);
        // 保存頭結(jié)點的指針
        struct Node * tmp = head;
        // 判斷是否有數(shù)據(jù)
        if(head != NULL) {
            // 有數(shù)據(jù)
            head = head->next;
            printf("del node, num : %d, tid : %ld\n", tmp->num, pthread_self());
            free(tmp);
            pthread_mutex_unlock(&mutex);
            usleep(100);
        } else {
            // 沒有數(shù)據(jù),需要等待
            // 當這個函數(shù)調(diào)用阻塞的時候,會對互斥鎖進行解鎖,當不阻塞的,繼續(xù)向下執(zhí)行,會重新加鎖。
            pthread_cond_wait(&cond, &mutex);
            pthread_mutex_unlock(&mutex);
        }
    }
    return  NULL;
}

int main() {

    pthread_mutex_init(&mutex, NULL);
    pthread_cond_init(&cond, NULL);

    // 創(chuàng)建5個生產(chǎn)者線程,和5個消費者線程
    pthread_t ptids[5], ctids[5];

    for(int i = 0; i < 5; i++) {
        pthread_create(&ptids[i], NULL, producer, NULL);
        pthread_create(&ctids[i], NULL, customer, NULL);
    }

    for(int i = 0; i < 5; i++) {
        pthread_detach(ptids[i]);
        pthread_detach(ctids[i]);
    }

    while(1) {
        sleep(10);
    }

    pthread_mutex_destroy(&mutex);
    pthread_cond_destroy(&cond);

    pthread_exit(NULL);

    return 0;
}

信號量

/*
    信號量的類型 sem_t
    int sem_init(sem_t *sem, int pshared, unsigned int value);
        - 初始化信號量
        - 參數(shù):
            - sem : 信號量變量的地址
            - pshared : 0 用在線程間 ,非0 用在進程間
            - value : 信號量中的值

    int sem_destroy(sem_t *sem);
        - 釋放資源

    int sem_wait(sem_t *sem);
        - 對信號量加鎖,調(diào)用一次對信號量的值-1,如果值為0,就阻塞

    int sem_trywait(sem_t *sem);

    int sem_timedwait(sem_t *sem, const struct timespec *abs_timeout);
    int sem_post(sem_t *sem);
        - 對信號量解鎖,調(diào)用一次對信號量的值+1

    int sem_getvalue(sem_t *sem, int *sval);

    sem_t psem;
    sem_t csem;
    init(psem, 0, 8);
    init(csem, 0, 0);

    producer() {
        sem_wait(&psem);
        sem_post(&csem)
    }

    customer() {
        sem_wait(&csem);
        sem_post(&psem)
    }

*/

#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>
#include <semaphore.h>

// 創(chuàng)建一個互斥量
pthread_mutex_t mutex;
// 創(chuàng)建兩個信號量
sem_t psem;
sem_t csem;

struct Node{
    int num;
    struct Node *next;
};

// 頭結(jié)點
struct Node * head = NULL;

void * producer(void * arg) {

    // 不斷的創(chuàng)建新的節(jié)點,添加到鏈表中
    while(1) {
        sem_wait(&psem);
        pthread_mutex_lock(&mutex);
        struct Node * newNode = (struct Node *)malloc(sizeof(struct Node));
        newNode->next = head;
        head = newNode;
        newNode->num = rand() % 1000;
        printf("add node, num : %d, tid : %ld\n", newNode->num, pthread_self());
        pthread_mutex_unlock(&mutex);
        sem_post(&csem);
    }

    return NULL;
}

void * customer(void * arg) {

    while(1) {
        sem_wait(&csem);
        pthread_mutex_lock(&mutex);
        // 保存頭結(jié)點的指針
        struct Node * tmp = head;
        head = head->next;
        printf("del node, num : %d, tid : %ld\n", tmp->num, pthread_self());
        free(tmp);
        pthread_mutex_unlock(&mutex);
        sem_post(&psem);
       
    }
    return  NULL;
}

int main() {

    pthread_mutex_init(&mutex, NULL);
    sem_init(&psem, 0, 8);
    sem_init(&csem, 0, 0);

    // 創(chuàng)建5個生產(chǎn)者線程,和5個消費者線程
    pthread_t ptids[5], ctids[5];

    for(int i = 0; i < 5; i++) {
        pthread_create(&ptids[i], NULL, producer, NULL);
        pthread_create(&ctids[i], NULL, customer, NULL);
    }

    for(int i = 0; i < 5; i++) {
        pthread_detach(ptids[i]);
        pthread_detach(ctids[i]);
    }

    while(1) {
        sleep(10);
    }

    pthread_mutex_destroy(&mutex);

    pthread_exit(NULL);

    return 0;
}

到了這里,關(guān)于第三章 Linux多線程開發(fā) 線程取消 屬性 同步 互斥鎖 死鎖 讀寫鎖 生產(chǎn)者消費者 信號量的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔相關(guān)法律責任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • C++多線程編程(第三章 案例1,使用互斥鎖+ list模擬線程通信)

    C++多線程編程(第三章 案例1,使用互斥鎖+ list模擬線程通信)

    主線程和子線程進行l(wèi)ist通信,要用到互斥鎖,避免同時操作 1、封裝線程基類XThread控制線程啟動和停止; 2、模擬消息服務(wù)器線程,接收字符串消息,并模擬處理; 3、通過Unique_lock和mutex互斥方位list 消息隊列 4、主線程定時發(fā)送消息給子線程; 代碼包含了XThread類(基類)、

    2024年02月15日
    瀏覽(20)
  • 計算機操作系統(tǒng)重點概念整理-第三章 進程同步【期末復習|考研復習】

    計算機操作系統(tǒng)重點概念整理-第三章 進程同步【期末復習|考研復習】

    計算機操作系統(tǒng)復習系列文章傳送門: 第一章 計算機系統(tǒng)概述 第二章 進程管理 第三章 進程同步 第四章 內(nèi)存管理 第五章 文件管理 第六章 輸出輸出I/O管理 給大家整理了一下計算機操作系統(tǒng)中的重點概念,以供大家期末復習和考研復習的時候使用。 參考資料是王道的計算

    2024年02月08日
    瀏覽(28)
  • Linux第三章

    Linux第三章

    無論是Windows、MacOS、Linux均采用多用戶的管理模式進行權(quán)限管理。在Linux系統(tǒng)中,擁有最大權(quán)限的賬戶名為:root(超級管理員) root用戶擁有最大的系統(tǒng)操作權(quán)限,而普通用戶在許多地方的權(quán)限是受限的(普通用戶的權(quán)限,一般在其HOME目錄內(nèi)是不受限的,一旦出了HOME目錄,大

    2023年04月26日
    瀏覽(32)
  • LINUX網(wǎng)絡(luò)第三章:DNS解析

    LINUX網(wǎng)絡(luò)第三章:DNS解析

    首先,我們要知道DNS是什么,DNS(Domain Name System)是域名系統(tǒng)的英文系統(tǒng),是一種組織成域?qū)哟谓Y(jié)構(gòu)和計算機和網(wǎng)絡(luò)服務(wù)命名系統(tǒng),用于TCP/IP網(wǎng)絡(luò)。、 DNS實際上是域名解析協(xié)議,將域名轉(zhuǎn)化為IP地址 在早期的域名解析的時候,是iana組織負責將域名和IP地址進行對應,并對其進

    2024年01月17日
    瀏覽(26)
  • Linux設(shè)備驅(qū)動——第三章字符驅(qū)動

    當對幸福的憧憬過于急切,那痛苦就在人的心靈深處升起?!涌?本章的目的是編寫一個完整的字符設(shè)備驅(qū)動。我們開發(fā)一個字符驅(qū)動是因為這一類適合大部分簡單的硬件設(shè)備。字符驅(qū)動也比塊驅(qū)動易于理解。本章的最終目的是編寫一個模塊化的字符驅(qū)動,但是我們不會在

    2024年02月08日
    瀏覽(24)
  • 『第三章』雨燕棲息地:Swift 開發(fā)環(huán)境

    『第三章』雨燕棲息地:Swift 開發(fā)環(huán)境

    咫尺春三月,尋常百姓家。為迎新燕入,不下舊簾遮。 翅濕沾微雨,泥香帶落花。巢成雛長大,相伴過年華。 雖然目前在 Linux 和 Windows 上也可適當?shù)男]幾發(fā) Swift 代碼,但要想正經(jīng)八百的學習 Swift 語言,macOS 還是舍我其誰般的最佳選擇。

    2024年02月08日
    瀏覽(24)
  • 第三章:Linux簡介及面試常問問題

    第三章:Linux簡介及面試常問問題

    目錄 一、Linux發(fā)展史 1.Linux前身-Unix 2.Linux誕生 3.開源文化 4.Linux系統(tǒng)特點 5.Linux操作系統(tǒng)優(yōu)點 6.Linux操作系統(tǒng)發(fā)行版 7.Linux內(nèi)核命名規(guī)則 二、Linux系統(tǒng)的安裝 三、linux系統(tǒng)分區(qū)簡介及如何分區(qū) 1.自動分區(qū) 2.手動分區(qū) 3.linux下查看分區(qū)信息和剩余空間大小 五、Linux系統(tǒng)的文件目錄結(jié)

    2024年02月16日
    瀏覽(17)
  • 第三章認識Node.js模塊化開發(fā)

    目錄 認識Node.js 概述 作用 基本使用 Node.js的運行 Node.js的組成 Node.js的語法 Node.js全局對象 認識模塊化開發(fā) 概述 場景 特點 模塊成員的導入和導出 Node.js?模塊化語法 導入模塊 導出模塊 ES6 模塊化語法 導入模塊 導出模塊 項目 認識Node.js 概述 Node.js是一個 開源的、跨平臺 的

    2024年02月06日
    瀏覽(23)
  • 微信小程序開發(fā)實戰(zhàn)課后習題解答————第三章(作業(yè)版)

    微信小程序開發(fā)實戰(zhàn)課后習題解答————第三章(作業(yè)版)

    一、填空題 1、微信小程序中用? ? navigationBar?? ? ?組件可以實現(xiàn)導航欄 2、?微信小程序中能夠?qū)崿F(xiàn)輪播效果的組件是? ? swiper? ? 3、?微信小程序中實現(xiàn)滾動條事件的綁定方法是 ? ?bindscroll?? 4、?微信小程序中引入音頻的組件是? ?InnerAudioContext?? 5、?微信小程序中控

    2024年02月09日
    瀏覽(96)
  • 移動開發(fā)技術(shù)_微信小程序_第三章測試

    作答記錄 1 【單選題】下列關(guān)于小程序生命周期函數(shù)說法不正確的是( )。(5.0分) A、 分為應用生命周期函數(shù)和頁面生命周期函數(shù)兩種 B、 在onLoad生命周期函數(shù)中可以獲得地址中的參數(shù) C、 onLaunch生命周期函數(shù)是小程序初始化完成時觸發(fā) D、 onLaunch 生命周期函數(shù)會被重復執(zhí)

    2024年02月09日
    瀏覽(23)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包