void* read_func(void* obj)
{
pthread_detach(pthread_self());
//pthread_cleanup_push(cleanup_handler, NULL);
const char* file = (const char*)(obj);
FILE* fp = fopen(file, "r");
if (!fp) return NULL;
char* line = new char [1024];
size_t len = 1024;
while (!feof(fp))
{
getline(&line, &len, fp);
if (len)
{
pthread_mutex_lock(&g_mutex);
task_queue.push_back(line);
pthread_cond_signal(&g_cond);
pthread_mutex_unlock(&g_mutex);
memset(line, 0, 1024);
}
};
fprintf(stdout, "read thread quit!\n");
free(line);
fclose(fp);
return NULL;
}
{
pthread_detach(pthread_self());
//pthread_cleanup_push(cleanup_handler, NULL);
const char* file = (const char*)(obj);
FILE* fp = fopen(file, "r");
if (!fp) return NULL;
char* line = new char [1024];
size_t len = 1024;
while (!feof(fp))
{
getline(&line, &len, fp);
if (len)
{
pthread_mutex_lock(&g_mutex);
task_queue.push_back(line);
pthread_cond_signal(&g_cond);
pthread_mutex_unlock(&g_mutex);
memset(line, 0, 1024);
}
};
fprintf(stdout, "read thread quit!\n");
free(line);
fclose(fp);
return NULL;
}