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
|
static void *StartUrlProcessing(void *VarUrlId)
{
UrlConnection* UrlConn = new UrlConnection;
unsigned long int a;
a = (unsigned long int)VarUrlId;
URL.UrlDomIndexKey[a] = a;
if (URL.UrlDomIndexKey[a] == 1)
{
UrlConn->UrlGetInfo(URL.UrlDomIndexKey[a],"www.google.com");
}
if (URL.UrlDomIndexKey[a] == 2)
{
UrlConn->UrlGetInfo(URL.UrlDomIndexKey[a],"www.google.ca");
}
if (URL.UrlDomIndexKey[a] == 3)
{
UrlConn->UrlGetInfo(URL.UrlDomIndexKey[a],"www.dmoz.org");
}
return NULL;
}
// then in the main function
int i;
pthread_t UrlThread[PSettings.Option_t];
int UrlID = PSettings.CurrentUrlID;
char *a;
for (i = 0; i <= PSettings.Option_t; i ++)
{
a = (char*)UrlID;
UrlID ++;
ThreadError = pthread_create(&UrlThread[i],NULL,StartUrlProcessing,(void *)a);
if( 0 != ThreadError)
{
fprintf(stderr, "Cound't run thread number %d, errorno %d\n",i,ThreadError);
}
else
{
fprintf(stderr, "Thread %d, gets UrlID Number %lu\n",i,PSettings.CurrentUrlID+i);
}
}
// Put in Destructor to shut down program
/* now wait for all threads to terminate */
for (i = 0;i <= PSettings.Option_t; i ++)
{
ThreadError = pthread_join(UrlThread[i], NULL);
fprintf(stderr, "Thread %d terminated\n", i);
};
|