Netwars

Jezyk C - watki

[#1]
17.05.2008 15:42

jak napisac program w c na watkach w Windowsie?

na linuxie mozna skorzystac z biblioteki <pthread.h>

#include <pthread.h>
#include <stdio.h>

void *threadFunc(void *arg)
{
char *str;
int i = 0;

str=(char*)arg;

while(i < 110 )
{
usleep(10000);
printf("threadFunc says: %s\n",str);
++i;
}

return NULL;
}

int main(void)
{
pthread_t pth; // this is our thread identifier
int i = 0;

pthread_create(&pth,NULL,threadFunc,"foo");

while(i < 100)
{
usleep(10000);
printf("main is running...\n");
++i;
}

printf("main waiting for thread to terminate...\n");
pthread_join(pth,NULL);

return 0;
}
kompilowalem za pomoca gcc nazwa.c -lpthread -o program i smigalo

jak to przerobic zeby sie odpalalo w Windowsie?
albo ma ktos jakis bardzo podstawowy przykladowy program?

[#2]
17.05.2008 15:55

printf("threadFunc says: %s\n",str);

pthread_join(pth,NULL);

po to Ci ta biblioteka ;p

[#3]
17.05.2008 16:08

tak tylko mi chodzi o to ze zeby ten program działał na Windowsie to trzeba dać inną bibliotekei coś zmienić bo z tą sie nie odpala

[#5]
19.05.2008 16:50

w windows wątki odpalasz funkcją CreateThread() (chyba jest w windows.h)

Zaloguj się, żeby odpowiedzieć.