클라이언트가 실행중인 두 개의 스레드가있는 클라이언트 서버 코드에서 작업하고 있습니다. 이 두 스레드가 60 초 동안 계속 실행되기를 바랍니다. 그러나 나는 두 가지 문제에 직면하고있다.스레드를 사용한 클라이언트 서버 프로그래밍
첫 번째로 main()
에서 for 루프를 실행할 때 bulk_thread()
이 생성하는 것처럼 임의의 숫자를 생성해야하는 동일한 번호가 retail_thread()
에 생성됩니다. 둘째, for 루프를 정확하게 60 초 실행한다는 아이디어를 얻을 수 없습니다.
숙제 문제이므로 정확한 해결책이 아니라면 어떤 힌트 나 도움을 주시면 감사하겠습니다. 있다면 오타를 무시하십시오.
int main(int argc, char *argv[]) {
int pt,i;
pthread_t thread;
/* n a very large number */
/* run below code for 60 seconds */
for(i=0;i<n;i++)
{
pt = pthread_create(&thread, NULL, retail_thread, (void*) NULL);
bulk_thread(NULL);
}
}
void* retail_thread(void*){
srand(time(NULL));
int order_size = rand()%20 + 1;
printf("in retail \n ");
sendtoserver_R(RETAIL_PORT,order_size);
int wait_time = 100 + (5*order_size);
printf("Retail thread order = %d and execution fully completed \n\n",order_size);
}
void* bulk_thread(void*){
srand(time(NULL));
int order_size = rand()%90 + 10;
printf("in bulk \n");
int wait_time = 100 + (5*order_size);
sendtoserver_B(BULK_PORT,order_size);
printf("Bulk thread order = %d and execution fully completed \n\n",order_size);
}
sendtoserver()
은 소켓을 만들고 서버에 데이터를 전송하기위한 것입니다.
? 그 순간에 여러 가지 스레드가 실행되어 다른 작업을 수행 할 수 있습니다. – alk
@ 바트 다음 번에는 그 사실을 명심하겠습니다. 고맙습니다!! – Vbp
@alk 그냥 서버가받은 주문 수를 계산하고 싶습니다. – Vbp