multithreading in linux

Below is a sample multithreading program based on C language.

# include
/* parameter that will be passed to each matrix */
struct v{

/* function that will be executed in each thread */
void *runonThread(void *param){
	struct v* data = (struct v*) param;
	/* put your application here */

int  main()
	pthread_t pid[NUMTHREADS];
	pthread_attr_t attr;
	/* get the default attributes */

	for(i=0; i... = ... ;
		/*passing 'data' as parameter to each thread*/
		pthread_create(&pid[i], &attr,
				runonThread, data);

	/*waiting for the threads to complete */
	for(i=0; i<NUMTHREADS; i++)
		pthread_join(pid[i], NULL);

	return 0;

You may download a sample application to count matrix multiplication that uses multithreads,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.