<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] ## 互斥量(鎖) - 兩個線程的指令交叉執行 - 互斥量可以保證先后執行 - 互斥量是**最簡單的線程同步的方法** - 互斥量(互斥鎖),處于兩態之一的變量:**解鎖和加鎖** - 兩個狀態可以保證資源訪問的串行 ### 方法 - 操作系統直接提供了互斥量的 API ( pthread_mutex_t ) - 開發者可以直接使用 API 完成資源的加鎖、解鎖操作 示例: <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 ``` ## 原子性 - 原子性是指一系列操作不可被中斷的特性 - 這一系列操作要么全部執行完成,要么全部沒有執行 - 不存在部分執行部分未執行的情況
                  <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>

                              哎呀哎呀视频在线观看