<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>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                [TOC] ## 讀寫鎖 - 讀寫鎖是一種**特殊的自旋鎖** - 允許多個讀者同時訪問資源以提高讀性能 - 對于寫操作則是互斥的 提供的api ``` pthread_rwlock_t pthread_rwlock_rdlock(讀鎖) pthread_rwlock_wrlock(寫鎖) ``` <details> <summary>main.cpp</summary> ``` #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <pthread.h> #include <vector> pthread_rwlock_t rwlock = PTHREAD_RWLOCK_INITIALIZER; int num =0; void *reader(void*){ int times = 100000; while(times--){ pthread_rwlock_rdlock(&rwlock); if (times % 1000==0){ printf("print num in reader:num%d\n", num); usleep(10); } pthread_rwlock_unlock(&rwlock) } } void *writer(void*){ int times = 100000; while(times--){ pthread_rwlock_wrlock(&rwlock); num++; pthread_rwlock_unlock(&rwlock); } } int main(){ printf("stat in main function."); pthread_t thread1,thread2,thread3; pthread_create(&thread1,NULL,&reader,NULL); pthread_create(&thread2,NULL,&reader,NULL); pthread_create(&thread3,NULL,&writer,NULL); pthread_join(thread1,NULL); pthread_join(thread2,NULL); printf("print in main function:num=%d",num); return 0; } ``` </details> <br />
                  <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>

                              哎呀哎呀视频在线观看