<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                [TOC] ### 生產者-消費者問題 `生產者(進程) -> 緩存區 -> 消費者(進程)` - 單從生產者程序或消費者程序去看是沒問題的 - 單兩者并發執行時就可能出差錯 >[warning] 根源問題:彼此相互之間沒有通訊 示例:又線程鎖與無線程鎖的區別 <details> <summary>main.cpp</summary> ``` #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <pthread.h> #include <vector> pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; int num =0; void *producer(void*){ int times = 10000000; while(times--){ // pthread_mutex_lock(&mutex); num++; // pthread_mutex_unlock(&mutex); } } void *comsumer(void*){ int times = 10000000; while(times--){ // pthread_mutex_lock(&mutex); num--; // pthread_mutex_unlock(&mutex); } } int main(){ printf("stat in main function."); pthread_t thread1,thread2; pthread_create(&thread1,NULL,&producer,NULL); pthread_create(&thread2,NULL,&comsumer,NULL); pthread_join(thread1,NULL); pthread_join(thread2,NULL); printf("print in main function:num=%d",num); return 0; } ``` </details> <br /> ``` g++ main.cpp -o main ./main ``` ## 臨界資源 - 臨界資源指的是一些雖作為共享資源卻又無法同時被多個線程共同訪問的共享資源。 - 當有進程在使用臨界資源時,其他進程必須依據操作系統的同步機制等待占用進程釋放該共享資源才可重新競爭使用共享資源。 ## 進程間的同步 空閑讓進:資源無占用,允許使用 忙則等待:資源有占用,請求進程等待 有限等待:保證有限等待時間能夠使用資源 讓權等待:等待時,進程需要讓出CPU ## 進程同步的方法 1. 消息隊列 2. 共享存儲 3. 信號量
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看