Fri Oct 17, 2008 1:24 pm
#include <iostream>
#include <pthread.h>
using namespace std;
#define threadCount 6
void *myThreadFunc(void *threadArg)
{
long numberOfThread;
numberOfThread = (long)threadArg;
cout << " Thread number now is:" << numberOfThread << endl;
pthread_exit(NULL);
}
int main ()
{
pthread_t threadArray[threadCount];
int status;
int i;
for( i=0; i < threadCount; i++ ){
cout << "main() - starting thread: #" << i << endl;
status = pthread_create(&threadArray[i], NULL,
myThreadFunc, (void *)i);
if (status){
cout << "error in creating a thread ," << status << endl;
exit(-1);
}
}
pthread_exit(NULL);
}
main() - starting thread: # 0
main() - starting thread: # 1
main() - starting thread: # 2
main() - starting thread: # 3
main() - starting thread: # 4
main() - starting thread: # 5
Thread number now is: 0
Thread number now is: 1
Thread number now is: 2
Thread number now is: 3
Thread number now is: 4
Thread number now is: 5
Tue Aug 11, 2009 12:01 am
Tue Aug 11, 2009 5:17 am
Tue Aug 11, 2009 8:32 am
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.