C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 12-04-2006, 08:39 PM   #1
Registered User
 
Join Date: Oct 2006
Posts: 58
Multi Threading

Hi everyone,


How do I create a multi threading program?
beon is offline   Reply With Quote
Old 12-04-2006, 08:56 PM   #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
Happy_Reaper is offline   Reply With Quote
Old 12-04-2006, 09:05 PM   #3
Registered User
 
Join Date: Nov 2006
Posts: 176
search around for pthread examples. fork() just creates a child process
sl4nted is offline   Reply With Quote
Old 12-04-2006, 09:05 PM   #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?
beon is offline   Reply With Quote
Old 12-04-2006, 09:14 PM   #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++
sl4nted is offline   Reply With Quote
Old 12-04-2006, 09:21 PM   #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. =)
beon is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
overlapped I/O and multi threading krishnampkkm C++ Programming 2 06-22-2009 03:27 PM
Looking for light cross platform Threading library umen242 C++ Programming 7 03-28-2008 04:23 PM
Singleton C++ Class - How to avoid mem leak in multi threading molus C++ Programming 6 06-02-2006 08:32 AM
starting to learn multi threading hanhao C++ Programming 2 06-09-2004 01:44 PM
Multi Threading IceBall C Programming 7 07-13-2003 03:01 PM


All times are GMT -6. The time now is 12:56 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22