C /C++のスレッド関数
このチュートリアルでは、C /C++のスレッド関数を理解するためのプログラムについて説明します。
スレッド関数を使用すると、ユーザーは並行関数を同時に実装できます。並行関数は、実行のために相互に依存することも、独立することもできます。
例
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
void* func(void* arg){
//detaching the current thread
pthread_detach(pthread_self());
printf("Inside the thread\n");
pthread_exit(NULL);
}
void fun(){
pthread_t ptid;
//creating a new thread
pthread_create(&ptid, NULL, &func, NULL);
printf("This line may be printed before thread terminates\n");
if(pthread_equal(ptid, pthread_self())
printf("Threads are equal\n");
else
printf("Threads are not equal\n");
//waiting for the created thread to terminate
pthread_join(ptid, NULL);
printf("This line will be printed" " after thread ends\n");
pthread_exit(NULL);
}
int main(){
fun();
return 0;
} 出力
This line may be printed before thread terminates Threads are not equal Inside the thread This line will be printed after thread ends
-
C /C++のスレッド関数
このチュートリアルでは、C /C++のスレッド関数を理解するためのプログラムについて説明します。 スレッド関数を使用すると、ユーザーは並行関数を同時に実装できます。並行関数は、実行のために相互に依存することも、独立することもできます。 例 #include <pthread.h> #include <stdio.h> #include <stdlib.h> void* func(void* arg){ //detaching the current thread pthread_detach(pthrea
-
C / C ++のAAツリー?
コンピュータサイエンスのAAツリーは、順序付けられたデータを効率的に保存および取得するために実装されたバランスの取れたツリーの形式として定義されます。 AAツリーは、エントリの効率的な追加と削除をサポートするバイナリ検索ツリーの形式である赤黒ツリーのバリエーションとして扱われます。赤黒木とは対照的に、AAツリーの赤いノードは、左のサブチャイルドではなく、右のサブチャイルドとしてのみ追加できます。この操作の結果、2-3-4ツリーではなく2-3ツリーのシミュレーションが行われるため、メンテナンス操作が簡素化されます。赤黒木のメンテナンスアルゴリズムでは、ツリーのバランスを適切にとるために、7つの異