pthread 쓰레드 중단하는 방법없을까요??

coder의 이미지

pthread라는걸 알게되어 한번 해보던도중 어떻게 해결해야할지 잘모르겠습니다 ㅠ

/////////////////////////////////////////////////

#include <stdio.h>
#include <windows.h>
#include <time.h>
#include <pthread.h>
 
void *thread_input(void*arg);
 
int gotoxy(int x, int y)
{
     COORD Pos;
     Pos.X = x;
     Pos.Y = y;
     SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Pos);
     return 0;
}
 
int main(void)
{
     int state;
     int main_i = 0;
     pthread_t t_id;
     state = pthread_create(&t_id, NULL, thread_input, NULL);
 
     while (1)
     {
         gotoxy(0, 0);
         printf("MAIN_THREAD : %d\n", main_i);
         main_i++;
     }
 
     return 0;
}
 
void *thread_input(void*arg)
{
    int input_i = 0;
    while (1)
    {
        gotoxy(0, 1);
        printf("INPUT_THREAD : %d\n", input_i);
        input_i++;
    }
 
    return 0;
}

/////////////////////////////////////////////////

위까지가 구글링해가며 짠소스입니다.

여기서 문제가되는 부분이요 thread_input이라는 쓰레드와 메인부분이 같이돌게되는데 thread_input쓰레드가 돌때 gotoxy(0, 1)에 가서 input_i의 값을 출력하고싶습니다. 그런데 gotoxy(0,1)에서 input_i가 출력될떄도 있지만 gotoxy(0, 1)까지만 thread_input이 돌고 바로 MAIN_THREAD를 출력하는 부분으로 넘어가니 gotoxy(0,1)부분에 main_i가 출력되기도합니다. 쓰레드를 실행할때 최소한 특정범위를 실행한 후에 다음 쓰레드로 넘어가게 하는 방법. 없을까요??(예를 들면 thread_input의 gotoxy(0,1)과 printf까지 실행된 후 다른 쓰레드로 넘어가게 하는것이요)

 의 이미지