日日操夜夜添-日日操影院-日日草夜夜操-日日干干-精品一区二区三区波多野结衣-精品一区二区三区高清免费不卡

公告:魔扣目錄網為廣大站長提供免費收錄網站服務,提交前請做好本站友鏈:【 網站目錄:http://www.ylptlb.cn 】, 免友鏈快審服務(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會員:747

pthread_equal()函數用于檢查兩個線程是否相等。它返回0或非零值。對于相等的線程,它將返回非零值,否則返回0。該函數的語法如下:

int pthread_equal (pthread_t th1, pthread_t th2);

登錄后復制

現在讓我們看看 pthread_equal() 的實際作用。第一種情況,我們會檢查自線程來檢查結果。

示例

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <pthread.h>
pthread_t sample_thread;
void* my_thread_function(void* p) {
   if (pthread_equal(sample_thread, pthread_self())) { //pthread_self will return current thread id
      printf("Threads are equal

"); } else { printf("Threads are not equal

"); } } main() { pthread_t th1; sample_thread = th1; //assign the thread th1 to another thread object pthread_create(&th1, NULL, my_thread_function, NULL); //create a thread using my thread function pthread_join(th1, NULL); //wait for joining the thread with the main thread }

登錄后復制

輸出

Threads are equal

登錄后復制

現在,如果我們在兩個不同的線程之間進行比較,我們將看到結果。

示例

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <pthread.h>
pthread_t sample_thread;
void* my_thread_function1(void* ptr) {
   sample_thread = pthread_self(); //assign the id of the thread 1
}
void* my_thread_function2(void* p) {
   if (pthread_equal(sample_thread, pthread_self())) { //pthread_self will return current thread id
      printf("Threads are equal

"); } else { printf("Threads are not equal

"); } } main() { pthread_t th1, th2; pthread_create(&th1, NULL, my_thread_function1, NULL); //create a thread using my_thread_function1 pthread_create(&th1, NULL, my_thread_function2, NULL); //create a thread using my_thread_function2 pthread_join(th1, NULL); //wait for joining the thread with the main thread pthread_join(th2, NULL); }

登錄后復制

輸出

Threads are not equal

登錄后復制

以上就是在C語言中,pthread_equal()函數用于比較兩個線程ID是否相等的詳細內容,更多請關注www.xfxf.net其它相關文章!

分享到:
標簽:C語言 pthread_equal() 線程ID
用戶無頭像

網友整理

注冊時間:

網站:5 個   小程序:0 個  文章:12 篇

  • 51998

    網站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會員

趕快注冊賬號,推廣您的網站吧!
最新入駐小程序

數獨大挑戰2018-06-03

數獨一種數學游戲,玩家需要根據9

答題星2018-06-03

您可以通過答題星輕松地創建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學四六

運動步數有氧達人2018-06-03

記錄運動步數,積累氧氣值。還可偷

每日養生app2018-06-03

每日養生,天天健康

體育訓練成績評定2018-06-03

通用課目體育訓練成績評定