1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
Downloader::downloadFile(thread_data* info)
{
/* ...... */
std::vector<CdownloadThread> vec;
info->distFile = Downloader::distFile;
info->file = Downloader::file;
info->hebergeur = Downloader::hebergeur;
info->localFile = Downloader::file;
info->downloaded = 0;
info->lastDownloaded = 0;
info->erreur = 0;
/* ...... */
pthread_t *threads;
threads = (pthread_t*) malloc( sizeof(pthread_t) * info->nbThread );
// taille a DL par thread
int quant = info->lengthFile / info->nbThread;
// Configure et lance chaque thread ( 6 par défaut)
vec.resize(info->nbThread);
int x= -1;
for(int i = 0 ; i < info->nbThread ; i++)
{
if( i == (info->nbThread - 1))
{
vec[i].idThread = i;
vec[i].startPoint= x + 1;
vec[i].quant = 0;
vec[i].backptr = info;
}
else
{
vec[i].idThread = i;
vec[i].startPoint= x + 1;
vec[i].quant = x + quant;
vec[i].backptr = info;
}
x += quant;
pthread_create(&threads[i], NULL, DownloadThread, (void *)&vec[i]);
}
for(int i = 0 ; i < info->nbThread ; i++)
{
pthread_join(threads[i], NULL);
}
/* ...... */
} |
Partager