Thread: Multi Threading

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    58

    Multi Threading

    Hi everyone,


    How do I create a multi threading program?

  2. #2
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    It depends on your platform. If you're on Linux, man the fork command.
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    176
    search around for pthread examples. fork() just creates a child process

  4. #4
    Registered User
    Join Date
    Oct 2006
    Posts
    58
    Hi Happy_Reaper,
    let say I'm using visual C++ v6, how would you suggest? I had never tried multi thread before. so basically I doesn't know how to. Is there anything I can look out for?

  5. #5
    Registered User
    Join Date
    Nov 2006
    Posts
    176
    I think windows has pthreads library, maybe not
    try this
    Code:
    #include <pthread.h>
    #include <stdio.h>
    #include <stdlib.h>
    
    void *hello(void *arg) {
      printf("hello world\n");
    }
    
    int main() {
      pthread_t thread_block;
      void *status;
    
      if (pthread_create(&thread_block, NULL, hello, NULL) != 0) {
        perror("pthread_create");
        exit(1);
      }
    
      if (pthread_join(thread_block, &status) != 0) {
        perror("pthread_join");
        exit(1);
      }
    
      return 0;
    }
    if not I donno...also this is the C Board, there is also a C++ one which you should probably have asked in since you're using C++

  6. #6
    Registered User
    Join Date
    Oct 2006
    Posts
    58
    Thanks sl4nted,
    To be true my program are in c, even though I use a visual c++ to compile. I'm kind of a green horn so I would really like to try everything. I'll try the example that are listed .. thanks alot. =)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. overlapped I/O and multi threading
    By krishnampkkm in forum C++ Programming
    Replies: 2
    Last Post: 06-22-2009, 03:27 PM
  2. Looking for light cross platform Threading library
    By umen242 in forum C++ Programming
    Replies: 7
    Last Post: 03-28-2008, 04:23 PM
  3. Replies: 6
    Last Post: 06-02-2006, 08:32 AM
  4. starting to learn multi threading
    By hanhao in forum C++ Programming
    Replies: 2
    Last Post: 06-09-2004, 01:44 PM
  5. Multi Threading
    By IceBall in forum C Programming
    Replies: 7
    Last Post: 07-13-2003, 03:01 PM