how to use multi threading in c

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Indianraja
    New Member
    • Apr 2007
    • 22

    how to use multi threading in c

    i want to perform two actions at an same time in c..... is it possible .... then how can we do that action?????
    for example... tak an car game.... we press the up arrow or some other key or accelaration... .. at the same time....neither key pressed nor not pressed, the amount of fuel or some timing wil decrease in the side of the screen...

    is it possible in c???? tel me d solution plz
  • gnanapoongothai
    New Member
    • Jun 2007
    • 62

    #2
    Originally posted by Indianraja
    i want to perform two actions at an same time in c..... is it possible .... then how can we do that action?????
    for example... tak an car game.... we press the up arrow or some other key or accelaration... .. at the same time....neither key pressed nor not pressed, the amount of fuel or some timing wil decrease in the side of the screen...

    is it possible in c???? tel me d solution plz
    u can go for dual core and then multiprogrammin g or multithreading .bcos in a single core even if u have all the application running its not running at the same time .

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      Dual core or not, you need to spawn a thread.

      How you do this is a little diffferent between Unix and Windows though the concept is the same:

      1) your thread is a function with prototypoe that fits a pattern:
      Windows: DWORD WINAPI ThreadProc(LPVO ID);
      Unix: void* ThreadProc(void *):

      2) You call an operating system function to create the thread and start it
      Windows: CreateThread()
      Unix: _pcreate_thread ()

      3) Your thread runs until the function completes. Then it dies.

      4) You may have communicate with your thread. Here you will need semaphores.

      5) Now a a good time to reasearch multithreading in your operating system.
      Windows: Plenty of info in MSDN.
      Unix: Use Google.

      Comment

      • gnanapoongothai
        New Member
        • Jun 2007
        • 62

        #4
        Multi threading program u can do . but one thread might be ruuning even if u write many threads in an application. if u practically want threads to run in parallel at the same time then hyperthreading technology or use dual core machine.

        Comment

        • Indianraja
          New Member
          • Apr 2007
          • 22

          #5
          i need the solution for that problem in c language.....

          Comment

          • alind
            New Member
            • Sep 2007
            • 7

            #6
            U can try for pthread or boost threads. Look for them on internet.

            Comment

            Working...