|
The contents of this page are licensed under the following license
Operating System
Threads |
#include <stdio.h>
#include <pthread.h>
/* thread function */
void* mytask(void* data)
{
int i;
for(i=0; i<10; i++)
{
sleep(1);
printf("Task of thread number: %d\n", *(int*)data);
}
}
int main()
{
pthread_t thread_1, thread_2;
int no1 = 1, no2 = 2;
int i;
/* create threads */
pthread_create(&thread_1, NULL, mytask, &no1);
pthread_create(&thread_2, NULL, mytask, &no2);
for(i=0; i<10; i++)
{
sleep(1);
printf("Main!\n");
}
/* wait for threads */
pthread_join(thread_1, NULL);
pthread_join(thread_2, NULL);
}
|
August, 23rd 2006
© Michał Kalewski