how do i?

hi,
how can i write a simple hallo world console program using threads with visual studio.

#include
#include
#include

#define NUM_THREADS 5

void *PrintHello(void *threadid)
{
int tid;
tid = (int)threadid;
printf("Hello World! It's me, thread #%d!
", tid);
pthread_exit(NULL);
}

int main (int argc, char *argv[])
{
pthread_t threads[NUM_THREADS];
int rc, t;
for(t=0; t<NUM_THREADS; t++){
printf("In main: creating thread %d
", t);
rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t);
if (rc){
printf("ERROR; return code from pthread_create() is %d
", rc);
exit(-1);
}
}
pthread_exit(NULL);
}

this is not working ! pthread header is not known. so how would i do it?
help will be appreciated higly.
also pls advice on the best book to go for when in it comes to win32 api c/c++.
thnx
chris

Comments

  • Hmm... does Visual Studio really support pthreads? I'd perhaps expect some other compiler to do so, but not stubborn MS. The only pthread support I know of for Win32 is open source wrapper libraries and such. There is no OS support for them, that's for sure.
  • http://msdn2.microsoft.com/en-us/library/ms811896.aspx#ucmgch09_topic4

    The above link is a discussion on how to port *nix programs to Win32. Scroll down a bit and there is a link to the "threads" topic.
    =============================================
    never lie -- the government doesn't like the competition. (Author unknown)
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion