Skip to content
Snippets Groups Projects
Select Git revision
  • main default protected
1 result

pcc

  • Clone with SSH
  • Clone with HTTPS
  • Kim Sunghoo's avatar
    Kim Sunghoo authored
    c35eab74
    History

    pcc007

    김성후

    202126312

    Class 1 - 23/02/06

    Linux 명령어

    ls : 현재 directory의 파일 목록을 보여줌

    ls (-l, -al) -l을 붙이면 더 자세한 정보 확인이 가능하며 -a를 붙이면 숨겨진 파일(.으로 시작하는 파일)도 보여줌

    cd : 다른 directory로 이동할 때 사용함

    cd (이동할 directory) 여기서 ..을 넣게 되면 이전 디렉토리로 바로 나갈 수 있음

    pwd : 현재 위치한 directory의 경로를 보여줌

    touch : 새로운 파일 생성

    touch (파일 이름)

    mkdir : 새로운 directory 생성

    mkdir (directory 이름)

    rm : 파일을 제거해줌

    rm (파일 이름)

    rmdir : directory를 제거해줌

    rmdir (디렉토리 이름)

    cat : 파일의 내용을 보여줌

    cat (파일 이름)

    ssh : 서버에 접속해줌

    ssh (계정)@(주소)

    passwd : ssh를 통해 접속한 게정의 비밀번호를 변경해줌

    vi : vi editor로 파일을 열어줌

    vi (파일이름) 없는 파일이름 이라면 새로 생성해줌

    cc : vi editor로 수정한 파일을 컴파일 해줌

    cc (파일 이름)

    ./a.out : cc를 통해 컴파일된 것을 실행해줌

    mv : 파일을 다른 위치의 directory로 옮겨줌

    mv (옮길 파일) (옮길 위치)

    cp : 파일을 복사하여 생성해줌

    cp (파일 이름) (생성할 파일 이름)

    ctrl + d : 진행중인 작업 중단

    ctrl + c : 진행중인 작업 kill

    exit, logout : bash를 종료할 때 쓰는 명령어

    vi editor

    i : insert 모드로 변경

    esc : insert모드에서 나옴

    yy : 줄 복사

    p : 붙여넣기

    dd : 줄 삭제

    :q : 나가기

    :wq : 저장하고 나가기

    • vi editor에서 명령어 앞에 숫자를 붙이면 그만큼 더 반복해줌

    2yy는 두줄 복사, 3yy는 세줄 복사

    그 외

    • hardware system의 정보교환 방향성 image-6.png
    • 표기법 i18n은 i와 n사이에 18개의 글자가 있다는 뜻 ex) localization은 l10n

    Class 2 - 23/02/07

    git 명령어

    git clone : 명령어를 통해 저장소를 복제해온다

    git pull : 원격 저장소에서 로컬 저장소로 파일을 가져옴

    git add : commit 하기 전에 파일을 모음

    git add *(전부라는 뜻)

    git commit : 변경된 내용을 기록

    git commit -> vi editor로 가서 기록 git commit -m "기록할 말" (-m을 추가하면 vi editor로 안넘어감)

    git push : commit된 프로젝트를 원격 저장소로 보냄

    Linux 명령어

    cc -o (원하는 이름) (c파일 이름) : ./a.out으로 캄파일된 파일을 실행할 필요 없이 원하는 이름으로 실행할 수 있게 해줌

    man : 명령어의 메뉴얼을 보여줌

    man (명령어)

    echo : 입력 문구 출력

    echo (문구)

    more, less : cat으로 보면 길게 나오는 내용을 한페이지씩 볼 수 있도록 해줌

    sleep : 설정한 초 동안 기다리기

    sleep (원하는 초)

    '|'(pipe) : A|B 라면 A의 stdout을 B의 stdin으로 사용한다는 뜻

    • 강의노트 내용 image-1.png

    • redirection

    '>' : (명령어) > (파일) 명령어의 표준 출력 스트림 도착 지점을 파일로 설정

    '<' : (명령어) < (파일) 파일로부터 입력을 받음

    '>>' : (명령어) >> (파일) 명령어의 표준 출력 스트림 도착 지점 파일에 내용 추가

    그 외

    • linux kernel image-5.png
    버퍼에서...
    • IOFBF : 모두 모아서 한번에 처리하는 것

    • IOLBF : 한 줄마다 처리하는 것

    • IONBF : 한 글자마다 처리하는 것

    • plush : 버퍼를 비워주는 명령어 stderr과 stdout의 우선 순위를 버퍼를 비워줌으로써 정해줄 수 있다

    • https://github.com/mug896 교수님이 알려주신 bash 관련 github 추후 관련 학습에 도움 될 것 같음

    Class 3 -23/02/08

    linux 명령어

    ps -l : 열려있는 bash와 shell 등의 목록을 보여줌

    sh : 새로운 쉘을 열어주는 명령어로 쉘을 열고 ps -l로 ppid를 살펴보면 bash에서 생성된 shell임을 확인할 수 있다 아래 사진 참고 image-2.png

    ; : bash에서 ;으로 명령어들을 이어주면 순차적으로 실행이 가능함

    home directory에서 mkdir test; ls -al을 입력해주면 test directory를 만든 후 그 안에 들어가서 ls -al을 실행하여준다

    c comfile

    c compile은 다음과 사진과 같이 진행된다 image-3.png

    단계별로 hello.c를 compile 한다고 했을 때 image-4.png

    1. gcc hello.c -o hello
    2. cpp hello.c > hello.i
    3. gcc -S hello.i
    4. as hello.i -o hello.o
    5. ld hello.o -o hello (ld hello.o -static -o hello)

    그 외

    • program의 3가지 상태는 실행중인 running, 작업이 끝난 kill, 실행은 안되지만 메모리에 남아있는 상태인 suspend

    Class 4 - 23/02/09

    Linux 명령어

    uname : 정보를 보여주는 명령어 (나는 linux)

    cc --static gen.c -o b.out : gen.c를 동적으로 컴파일 한다. out은 b.out

    ldd : 어던 라이브러리가 필요하는지 확인하는 명령어 (b.out이 동적인지 확인 했었음)

    vi editor 명령어

    c : 한 글자 바꾸기

    cc = 한 줄 바꾸기

    • vi 에서 두번 입력하면 그 줄을 의미한다 (yy역시 마찬가지)

    type basic

    • 변수의 type이 차지하는 memory를 외운 바가 있으나(ex. int : 4byte) 사실은 이것과 다르다. 아래 표 참고

    image-7.png

    • 실습으로 sizeof 함수를 통해 확인하였음
    
    #include <stdio.h>
    int main()
    {
    	printf("char : %ld\n", sizeof(char));
    	printf("int : %ld\n", sizeof(int));
    	printf("long : %ld\n", sizeof(long));
    	printf("long long : %ld\n", sizeof(long long));
    	printf("short : %ld\n", sizeof(short));
    	printf("pointer : %ld\n", sizeof(char *));
    	return 0;
    
    }
    
    • 이 코드가 담긴 c파일을 컴파일 하고 ./a.out을 통해 실행하면 현재 내 컴퓨터에서 각 type이 몇 바이트를 요구하는지 알 수 있다.

    • cc -m32 mem_test.c -o b.out을 통해 mem_test.c 파일을 32비트로 컴파일하고 b.out에 저장한 후 실행하면 값이 달라진다.

    그 외

    • 컴파일은 두 종류이다. 한줄씩 하는 인터프리터, 한번에 다 하는 컴파일러

    • loader : 스토리지에 있는 실행 파일을 로딩 해주는 것

    Class 5 - 23/02/10

    Linux 명령어

    clear : 버퍼를 모두 지워줌

    !$ : 가장 최근 명령어의 마지막 파라미터를 쓸 때 사용한다.

    alias : 명령어를 자신이 편한 이름으로 지정할 수 있다.

    alias (원하는 이름)="명령어"

    unalias : alias로 지정한 명령어들을 해제할 수 있다.

    alias (-a, -p) -p는 지정된 목록을 확인할 수 있고 -a 모든 alias 설정을 취소할 수 있다.

    C Prepocessor(CPP)

    * Preprocessor는 "#"으로 시작되는 문법끼리 다루어진다.
    • #difine, #include 같은 지시문들은 Preprocessor에 의해 다루어진다.

    #include : 특정한 파일을 열어서 컴파일하는 파일의 한 부분으로 포항(include)하도록 Preprocessor에 명령한다.

    #define : 상수나 자주 쓰이는 기능을 일종의 매크로로 저장한다.

    • Conditional Compilation (조건부 컴파일) 말 그대로 조건에 맞는 컴파일을 하는 것.

    #ifm, #ifdef, #ifndef, #else, #elif, #endif로 구성된다.

    image8.png

    • #error를 이용하여 원하는 에러를 출력할 수 있다.

    #error (원하는 문구)를 입력하면 문구와 함께 에러가 출력된다.

    • #line을 이용해 라인의 번호와 컴파일러에 보고된 파일의 이름을 바꿀 수 있다.

    #line 2000 "string" 를 입력 후 그 다음줄에 #error를 입력한다면 string 파일의 2000번째 줄에서 에러가 발생한 것으로 출력된다.

    • LINE 현재 줄 번호를 알려준다.

    • FILE 현재 파일 이름을 알려준다.

    
    #include <stdio.h>
    
    int main()
    {
    #ifdef __PCC_M32
            printf("char : %d\n", sizeof(char));
            printf("int : %d\n", sizeof(int));
            printf("long : %d\n", sizeof(long));
            printf("long long : %d\n", sizeof(long long));
            printf("short : %d\n", sizeof(short));
            printf("pointer : %d\n", sizeof(char *));
    #else
            printf("char : %ld\n", sizeof(char));
            printf("int : %ld\n", sizeof(int));
            printf("long : %ld\n", sizeof(long));
            printf("long long : %ld\n", sizeof(long long));
            printf("short : %ld\n", sizeof(short));
            printf("pointer : %ld\n", sizeof(char *));
    #line 2000 "string"
            printf("%d : %s\n", __LINE__, __FILE__);
    #error ddddddd
    #endif
            return 0;
    
    }
    

    위의 코드를 실행하면 __PCC_M32가 정의되지 않았으므로 #else에 있는 코드가 출력되고 이후 라인 번호(2000) : string(파일 이름)이 출력된다.

    Class 6 - 23/02/13

    C에서 연산자의 우선순위

    image-11.png

    새로 배운 출력에서의 기호

    • %p : 프린트 함수에서 주소를 출력해줌

    C의 기본 자료형

    • [unsigned , signed] X [long long int (long), short, char], float, double, (half, quad)

    숫자의 표현 float(IEEE 754)

    • sign 1 bit, exp 8 bits (bias = 127), mantissa or fraction 23 bits

    image-9.png

    ex) fixed FX_S03_04 (Q=4)

    image-10.png

    b7 은 sign bit 로 – 1 이면 2의 보수로 변경

    if (b7 == 1 )  
        –(~b6 * 22 + ~b5 * 21 + ~b4 * 20 + ~b3 * 2-1 + ~b2 * 2-2 + 
               ~b1 * 2-3 + ~b0 * 2-4 + 2-4) 
    else
         b6 * 22 + b5 * 21 + b4 * 20  + b3 * 2-1 + b2 * 2-2 + b1 * 2-3 + b0 * 2-4 
      x 2-q
    

    나의 Project FX_S5706

    • 부호 비트 : 1 (signed)

    • 소수점 위의 비트 : 57

    • 소수점 아래 비트 : 6

    • 구현할 때 long long을 이용할 것

    32비트와 64비트로 컴파일 하는 법

    typedef int fx_s17_14;
    typedef fx_s17_14 fixed;

    MISRA_C Rule

    • no int, no float
    In code fragments the following typedef’d types have been assumed (this is to comply with Dir 4.6):
    uint8_t /* unsigned 8-bit integer */
    uint16_t /* unsigned 16-bit integer */
    uint32_t /* unsigned 32-bit integer */
    int8_t /* signed 8-bit integer */
    int16_t /* signed 16-bit integer */
    int32_t /* signed 32-bit integer */
    float32_t /* 32-bit floating-point */
    float64_t /* 64-bit floating-point */
    
    bool		/* No typede */
    wchar_t 	/* no typedef */
    
    Non-specific object names are constructed to give an indication of the type. For example:
    uint8_t u8a; /* 8-bit unsigned integer */
    int16_t s16b; /* 16-bit signed integer */
    int32_t s32c; /* 32-bit signed integer */
    bool_t bla; /* essentially Boolean */
    enum atag ena; /* enumerated type */
    char chb; /* character */
    float32_t f32a; /* 32-bit floating-point */
    float64_t f64b; /* 64-bit floating-point */

    Three basic memory model in C (번역본 보다 영어 표현이 더 정확함)

    *Automatic

    Declare a variable on first use > removed when it goes out of scope.

    *Static

    exist in the same place throughout the life of the program. Array sizes are fixed at startup, but values can change Data is initialized before main starts, - and thus any initializations have to be done with constants that require no calculations. Variables declared outside of functions (in file scope) and inside functions with the static keyword are static. If you forget to initialize a static variable, it is initialized to all zeros (or NULL).

    *Manual

    The manual type involves malloc and free, only type of memory where arrays can be resized after declaration.

    Dynamic Array - malloc(동적 배열)

    • malloc : allocate from heap(여기서 heap는 컴퓨터의 기억 장소에서 그 일부분이 프로그램들에 할당되었다가 회수되는 작용이 되풀이되는 영역)

    • realloc : change size of memory

    • calloc : allocate memory and set 0

    • free : return memory to heap

    Noun-Adjective Form (Rule of thumb)

    • int const : A constant integer ( == const int )

    • int const * : A (variable) pointer to a constant integer

    • int * const : A constant pointer to a (variable) integer

    • int * const * : A pointer to a constant pointer to an integer

    • int const * * : A pointer to a pointer to a constant integer

    • int const * const * : A pointer to a constant pointer to a constant integer

    • int const * const * const A : constant pointer to a constant pointer to a constant integer

    위의 type, pointer, constant를 이용한 실습

    #include <stdio.h>
    
    int main()
    {
            int a[2] = {10, 10};
            int const *b = a;
    
            int sum = b[0]+b[1];
            int product = b[0]*b[1];
    
            printf("%d %d\n", a[0], a[1]);
            printf("%p %d %p %d\n",b , *b, &b,(long long)b- (long long) (&b));
    }

    이 코드는 b가 가리키는 값(a[0]과 a[1])의 합과 곱을 계산하고 각각 sum, product에 저장한다. 그 후 a[0]과 a[1]에 어떤 값이 저장되어있는지 출력하고 포인터 b 자체의 값, b가 기키는 값(a[0]), b의 주소, b와 포인터 b의 주소 간의 차이를 출력한다.

    출력 결과를 살펴보았을 때 마지막 b와 포인터 b의 주소간의 차이는 8byte인데 이유는 b가 가리키는 int형 데이터(4byte)가 할당된 메모리 영역 다음에 'b'의 주소가 위치하고 있기 때문이다. 또한 8byte는 x86 아키텍쳐에서 4바이트 정수형 변수와 4바이트 포인터 변수가 서로 떨어진 거리이다.

    Class 7 - 23/02/14

    포인터 기본

    • 자료형의 바이트 수 생각하면서 볼 것

    &val - Address of val *ptr – Value in address val

    int *a; 	// a++ increment by 4
    long long *b 	// b++ increment by 8 
    void *c  	// c++ increment by 1
    int vector[] = {100, 200, 300};
    int *p0 = vector; 
    int *p1 = vector + 1; 
    int *p2 = vector + 2;

    프린트에서 출력

    • %x, %o, %d - 16진수, 8진수, 10진수
    • %p - 주소를 출력해줌

    function Call Memory (기억할 것)

    image-12.png image-13.png

    • 동적으로 할당된 메모리 영역은 heap에 저장

    교수님이 보여준 포인터 예시

    • double (*f[10])(int const *a, double (*g[10])(double h));

    휴대폰에 들어가있는 코드라고 하심 중요한듯.

    • 설명

    f is Array (size 10) of functions return type is double parameter a is int const, parameter g is array (size 10) of function return type is double parameter h is double

    • 실습 pointer
    #include <stdio.h>
    #include <stdlib.h>
    
    int * func ()
    {
            int * p;
            p = (int *) malloc(8);
            p[0] = 500;
            printf("func:%d %p %p\n", *p, p, &p);
            return p;
    }
    int main()
    {
            int     *ppp=NULL;
            printf("main:%p %p\n", ppp, &ppp);
            ppp = func();
            printf("main:%d %p %p\n", *ppp, ppp, &ppp);
            return 0;
    }
    • 이 코드에서 변수들의 주소가 저장되는 과정을 살펴보자

    이 코드에서 포인터 변수 ppp의 주소는 main함수의 스택 프레임 안에 있고 ppp가 가리키는 메모리 주소는 동적으로 할당된 메모리 영역(heap)에서 할당된 메모리 주소이다.

    코드를 실행하면 func()에서 malloc을 통해 8바이트의 메모리를 동적으로 할당하는데 여기서 malloc 함수가 반환하는 주소는 할당된 메모리의 시작 주소이다. 이 주소를 a라고 하였을 때 p 변수는 주소 a 번지에 저장된다.

    그리고 p[0]에 500을 할당하는데 여기서 p[0]는 *(p+0)와 같다. 즉, p가 가리키는 메모리의 첫번째 자리이므로 아까 malloc이 반환한 주소 a에 500을 저장하는 것이다.

    이후 함수 func는 p 변수를 반환하는데 이때 반환하는 값은 p의 값으로 할당된 메모리 블록의 시작 주소이다. 즉, 반환되는 값의 주소가 b라면 b번지에는 p의 값인 a가 이 저장되어있는 것이다.

    이 반환된 주소가 ppp에 저장되는데 ppp 변수의 주소를 c라고 한다면 ppp는 c에 저장되고 가리키는 주소는 p가 가리키는 메모리의 시작 주소인 b인 것이다.

    따라서 ppp의 값인 *ppp를 출력하면 500이 출력되는데 ppp가 가리키는 메모리의 첫 번째 자리에 500이 저장되어 있기 때문이다. 또 ppp 변수의 값과 ppp변수의 주소를 출력하면 각각 a와 c가 출력되는 것이다.

    Class 8 - 23/02/15

    gdb-GNU-Debugger

    • C compile은 다음과 같은 순서로 진행된다 image-3.png

    • gcc compile의 옵션은 여러가지가 존재한다

    -c : generate .o file -g : for debug -O# : Optimization -E : generate preprocessing -pg : for profile -m32 -m64 : machine target

    Optimization

    • gcc의 옵션인 -pg를 통해 실행 시간 및 호출 정보 등을 프로파일링 데이터로 생성해준다. 여기에 gprof같은 프로파일링 도구를 이용하여 데이터를 시각적으로 확인 할 수 있다.

    • gprof를 통해 얻은 데이터와 call graph image-15.png

    image-14.png

    • 어떤 것이 다른 결과를 가져오는가? (Golden Rule)

    Speed - CPU > Memory > Storage > IO > Human Register > Cache (1st, 2nd) > Memory > ... Locality Pipeline Error

    Pipe Line

    • 파이프라인의 기본적인 원리는 사진과 같다 image-16.png

    Fetch: 명령어를 가져오는 단계

    Decode: 명령어를 해독하는 단계

    Execute: 명령어를 실행하는 단계

    Memory: 데이터 메모리를 읽거나 쓰는 단계

    Write: 실행 결과를 레지스터에 저장하는 단계

    • 하나씩 위의 과정에 따라 순서대로 진행되는 작업을 동시에 진행하게 해주는 일종의 병렬연결

    ex. 하나의 작업이 Write 단계에 있을 때 다른 작업은 ID 단계를 시작하는 것

    • cortex-M7 pipeline image-17.png

    • coretex-M7은 임베디드 시스템에 사용되는 제품이다

    • ARM 9 - CPI image-18.png

    • ARM Compile (optimization) image-19.png

    gcc-Optimization

    • Options Meaning

    O0(기본값) 최적화를 수행하지 않는다.

    O 코드 크기와 실행 시간을 줄이는 것을 제외한 최적화는 실행하지 않는다.

    O1

    O2 메모리 공간과 속도를 희생하지 않는 범위내의 모든 최적화를 수행한다.

    loop unrolling과 function inlining에 대한 최적화를 수행하지 않는다.

    O3 -O2 최적화에 인라인 함수와 레지스터에 대한 최적화를 추가로 수행한다.

    Os -O2 최적화 기능을 사용하지만, 코드 크기를 증가시키는 최적화는 생략한다.

    Class 9 - 23/02/16

    Make (GNU make)

    • Lots of source files: foo1.h, foo2.h, foobar1.cpp….

    • How to manage them all

    • Compiling is not easy * different target system * different purpose of compiling – debug, release, preprocessor… * compile what we need to * dependency

    • Solution is *make

    How dows make work

    • by description of Makefile * given targets (usually file to be created) * Specify dependencies for each target * Give command to create target from dependencies * make recursively build targets from dependencies * recompilation – time-stamp of modification

    Automatic Variables - Basic

    image-20.png

    Automatic Variables - File and Directory

    image-21.png

    Pre-defined Macro

    image-22.png

    • make의 장점

        * 각 파일에 대한 반복적 명령의 자동화로 인한 시간 절약
        * 프로그램의 종속 구조를 빠르게 파악할 수 있으며 관리가 용이
        * 단순 반복 작업 및 재작성을 최소화
    • Makefile의 구성

        * 목적파일(Target) : 명령어가 수행되어 나온 결과를 저장할 파일
        * 의존성(Dependency) : 목적파일을 만들기 위해 필요한 재료
        * 명령어(Command) : 실행되어야 할 명령어들
        * 매크로(Macro) : 코드를 단순화 시키기 위한 방법
    • make 파일 작성

    파일 : 파일을 만드는데 필요한 구성요소들
        명령 1
        명령 2
        ...

    ex. image-23.png

    • 더미타겟

        *파일을 생성하지 않는 개념적인 타겟
    clean :
        \rm *.o projectfile
    

    ex. image-24.png

    CMAKE

    • CMake is build system generator

    • Mission

    The CMake system makes it easier to build, test, and package C++ projects. Cmake helps teams to develop high quality, well-tested, cross-platform code with confidence

    • Why we need new solution

    make is based on shell command, limitation in huge project

    요구 CMake 최소 버전

    CMAKE_MINIMUM_REQUIRED ( VERSION 2.8 )

    프로젝트 이름 및 버전

    PROJECT ( "andromeda" )
    SET ( PROJECT_VERSION_MAJOR 0 )
    SET ( PROJECT_VERSION_MINOR 1 )

    빌드 형상(Configuration) 및 Makefile 생성 여부

    SET ( CMAKE_BUILD_TYPE Debug )
    SET ( CMAKE_VERBOSE_MAKEFILE true )

    Class 10 - 23/02/17

    Thread(쓰레드)

    • CPU(Central Processing Unit) : 명령어를 해독하고 실행하는데 필요한 모든 기능을 가지고 있음 (컴퓨터의 두뇌 역할) 컴퓨터의 성능은 CPU의 속도와 코어 수에 따라 결정되고 코어가 많은 CPU는 한번에 여러 작업을 처리할 수 있으므로 더 빠른 작업 속도를 제공한다.

    • CPU Code (intel i7-980x) image-25.png

    • Thread : A thread is a unit of execution on concurrent programming. Multithreading is a technique which allows a CPU to execute many tasks of one process at the same time. These threads can execute individually while sharing their resources. (일종의 병렬 처리 장치)

    • Core vs Thread (코어와 쓰레드의 차이) image-26.png image-27.png

    • Process create by fork and clone

    #include <sys/types.h>
    #include <unistd.h>
     pid_t fork(void);
    
     #define _GNU_SOURCE
    #include <sched.h>
    long clone(unsigned long flags, void *child_stack, 
    	int *ptid, int *ctid, unsigned long newtls);
    • system - system call
    #include <stdlib.h>
    int system(const char *command);
    execl("/bin/sh", "sh", "-c", command, (char *) 0);
    int execl(const char *path, const char *arg, ... 
              /* (char  *) NULL */);
    • thread.h (C11)
    #include <threads.h>
    #include <stdio.h>
    
    int run(void *arg)
    {
        printf("Hello world of C11 threads.");
        return 0;
    }
    
    int main(int argc, const char *argv[])
    {
        thrd_t thread;
        int result;
        thrd_create(&thread, run, NULL);
        thrd_join(&thread, &result);
        printf("Thread return %d at the end\n", result);
    }
    
    • pthread.h (POSIX)
    #include <pthread.h>
    #include <stdio.h>
    
    void *run (void *arg)
    {
        printf("Hello world of POSXI threads.");
        return 0;
    
    }
    
    int main()
    {
    	pthread_t thread;
    	int result; 
    	pthread_create(&thread, NULL, run, NULL );
    	pthread_join(thread, &result);
    	printf("Thread return %d at the end\n", result);
    }
    
    • POSIX : POSIX Thread의 약자로 유닉스 계열 POSIX 시스템에서 병렬적으로 작동하는 소프트웨어를 작성하기 위하여 제공하는 API(쓰레드를 편하게 만들 수 있게 도와주는 API)

    API : API는 Application Programming Interface의 약자로 응용 프로그램에서 다른 응용 프로그램과 상호 작용할 수 있도록 인터페이스를 제공하는 소프트웨어 개발 도구. API는 보통 프로그램 개발자들이 다른 프로그램과 상호 작용할 수 있도록 필요한 함수, 클래스, 메서드, 프로퍼티 등을 제공한다. 이를 통해, 개발자는 다른 응용 프로그램에서 제공하는 기능을 호출하거나, 데이터를 전송하거나, 처리할 수 있다.

    • pthread.h API (1)
    int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg);
    (생성 함수 start_routine을 실행)
    void pthread_exit(void *retval);
    (retval must not in stack)
    (main thread exit with this, other threads are still running)
    int pthread_join(pthread_t thread, void **retval);
    • pthread.h API (2)
    void pthread_cancel(pthread_t thread);
    (Send cancellation request to thread)
    pthread_t pthread_self(void);
    (return ID of the calling thread)
    int pthread_equal(pthread_t t1, pthread_t t2);
    (compare thread IDs)
    • thread 에서 pointer 공유
    pthread_mutex  mutexSum; 
    int *sum; 
    mutexInit()
    {
    	pthread_attr_t attr; 
    	pthread_mutex_init(&mutexSum, NULL);
    	pthread_attr_init(&attr);
    	pthread_attr_setdetachstate(&attr, PTHREAD_CREADTE_JOIANBLE);
    }
    
    sumFunc(int a)
    {
    pthread_mutex_lock(&mutexSum);
    *sum += a;
    pthread_mutex_unlock(&mutexSum);
    pthread_exit((void *) 0); 	
    }
    
    • Data Structure Library : GLib

    libglib2.0-dev package : $ pkg-config glib-2.0 --cflag --libs -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -lglib-2.0 Supported Data Structure : Array, AsyncQueue, BookmarkFile, ByteArray, Bytes, Checksum, Cond, Data, Date, DateTime, DebugKey, Dir, Error, HashTable, HashTabelter, Hmac, Hook, HookList, Iconv, IOChannel, IOFuncs, KeyFile, List, LogField, MainContext, MainLoop, MappedFile, MarkupParseContext, MarkupParser, MatchInfo, MemVTable, Node, Once, OptionContext, OptionEntry, OptionGroup, PatternSpec, PollDF, Private, PtrArray, Queue, Rand, RecMutex, Regex, RWLock, Scanner, ScannerConfig, Sequence, SequenceLter, Slist, Source, SourceCallBackFuncs, SourceFuncs, StatBuf, Striing, StringChunk, StrvBuilder, TestCase, TestConfig, TestLogBuffer, TestLogMsg, TestSuite, Thread, ThreadPool, Timer, TimerVal, TimeZone, TrashStack, Tree, TreeNode, URI, UriOaramslter, Variant, VariantBuilder, VariantDict, Variantlter, VariantType Unions : IEEE754 Double/Float, Mutex, TokenValue

    • Testing tools

    Cunit - C Unit test : 소스 코드의 작은 단위인 함수, 모듈, 클래스 등의 개별 단위를 테스트하는 것. 유닛 테스트는 소스 코드의 일부분을 변경할 때, 이를 검증하는 데 사용된다. 테스트는 이러한 변경 사항이 예상대로 작동하는지 확인하고, 코드에 잠재적인 버그를 찾아내는 데 도움을 줄 수 있다.

    cppcheck - C/C++ static code analyzer : C와 C++에서 가능한 버그와 코드 스타일 문제를 탐지하는 도구. C/C++ 코드에 대한 정적 분석을 수행한다. 즉, 코드를 실행하지 않고 소스 코드를 분석하여 문제를 찾는 것. Cppcheck는 메모리 누수, 잘못된 포인터 사용, 오버플로우, 언더플로우, 인자 전달 문제, 잘못된 형식 문자열 사용, 비정상적인 반환값 등 다양한 문제를 찾을 수 있습니다. (MISRA-C - python misra.py file.c.dump)

    Coverage Tool image-28.png