hi,
if (CLIENT_HANDLER_THREAD_CREATION_POLICY == POLICY_PRE_CREATE)
{
int id[NUMTHREADS];
for (int i = 0;i < NUMTHREADS;i++)
{
int id = i;
int status = pthread_create(&client_request_handler_threads[i], NULL, handle_client_requests, &id[i]);
}
}
void* handle_client_requests(void* id)
{
//printf("server threads spawnd\n");
// create log file
thread_id = pthread_self();
sprintf(log_file_name,"t%d.log",thread_id);
log_file = fopen(log_file_name, "w");
// todo: dynamically allocate storage
char log_msg[5000];
int tid = *((int*)id);
printf("id: %d\n",tid);
sprintf(log_msg,"thread id: %d\n",tid);
write_to_log_file(log_msg);
}
I am not sure why the output is:
id: -718438848
id: 32563
id: -1205030144
id: -1213790742
from where did this garbage values come from?
Thanks.