Greatest C++ Doubt

This is a discussion on Greatest C++ Doubt within the C++ Programming forums, part of the General Programming Boards category; Hi there again, I have the greatest doubt.. I doubt any one can solve it.. Who ever solves this, i ...

  1. #1
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683

    Greatest C++ Doubt

    Hi there again,
    I have the greatest doubt.. I doubt any one can solve it.. Who ever solves this, i agree is the greatest programmer..
    How do you make a part of the program to kepp running when the program is waiting for an input from the user....


    That's it sounds simple, dosent it.. Try

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Using threads. Run your background processing in one or more worker thread(s) with your UI in another.

    How, depends to a great deal on the OS. Most *NIX systems use the POSIX threading model, (commonly called pthreads), Windows has it's own model, but is actually very similar.

    >>> That's it sounds simple, dosent it.. Try

    I have. I routinely multithread my programs.

    Incidently, threading is one way of doing it, probably the easiest. There are other asynchronous techniques.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    114
    Hey! I knew that to! Means i'm a great programmer now!

    *lol*

    As Adrian says, how threads are implemented differs from OS to OS. This is why you should take great caution when using treads in your "platform independant project". Threads will in a such project be a portion of the code you must rewrite when switching platform. Of cause there is always a solotion to this to!

    Happy coding!

  4. #4
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    Ok i use Windows Platform and use the Turbo C++ 3.0 comiler. So how do i do it here..... Please help me...

  5. #5
    Fingerstyle Guitarist taylorguitarman's Avatar
    Join Date
    Aug 2001
    Posts
    564
    Include the windows.h header and look into the functions related to CreateThread().
    If a tree falls in the forest, and no one is around to see it, do the other trees make fun of it?

  6. #6
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    You should update your compiler to a decent one too. Borland has released its command line compiler for free. not perfect but miles better than turbo c++.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  7. #7
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    I can't comment on a compiler that old, but certainly with VC and the more recent Borland compilers, CreateThread() can cause problems. Both Borland and MS provide a function _beginthread() which is a better deal. If you need more control, there is _beginthreadex() from MS or _beginthreadNT() from Borland. Remember however, that the more sophisticated version do not release the thread handle, you must do that yourself. If you don't need the extras that they give, use _beginthread().
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  8. #8
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    To do it, use a macro at the top and create a generic name that is defined to windows style if run on windows. Else, have it defined to use the Linux version if it detects it's on a Linux machine.

  9. #9
    Fingerstyle Guitarist taylorguitarman's Avatar
    Join Date
    Aug 2001
    Posts
    564
    I remember adrian saying that before so I did a little searching.

    This comes from the MS platform SDK
    A thread that uses functions from the C run-time libraries should use the _beginthread and _endthread C run-time functions for thread management rather than CreateThread and ExitThread. Failure to do so results in small memory leaks when ExitThread is called.

    Perhaps useful info.
    If a tree falls in the forest, and no one is around to see it, do the other trees make fun of it?

  10. #10
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    Question Borland

    I use borland... In this situation how might I go about making a thread?

  11. #11
    Registered User
    Join Date
    Aug 2001
    Posts
    223

    what about

    OK I will admit that multi-threading is the best and most obvious solution but what about..... The third best solution (it certainly cannot be the next best) for someone not ready for multi-threading just yet.
    I have not tested the code but with some minor adjustments it should work....
    I realize that this cannot replace multi-threading but at least it can allow processes to run while until the user enters a key.


    Code:
    .....
    
    int i = 0;
    
    
    while( 1 )
    {
    
       while( !kbhit() )
       {
          // do this or the other.......
       }
    
        int chVal = getch();
    
        szEntry[i++] = (char)chVal;
    
        szEntry[i] = '\0';
    
        if( strcmp(szEntry, "desired input") == 0)
       {
               dosomething(); 
               strcpy(szEntry, "");
               i = 0;
      }
    
        else if( strcmp(szEntry, "quit") == 0)
              break;
    }
    zMan

  12. #12
    Intranasal Heroin User Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,035
    vasanth....we already went over this!

  13. #13
    I'm Back
    Join Date
    Dec 2001
    Posts
    556
    check this -->

    http://www.cprogramming.com/cboard/s...threadid=11925

    edit:
    I AM THE GREATEST C++ PROGRAMMER. BOW DOWN BEFORE ME...


  14. #14
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    We went over this i agree. Byt that dint answer my question. But threads seems to be my answer.. But there is no _beginthread in my compiler.. And the bad thing about Borland compiler is that it does not have an ide environment.. Well I need more help

  15. #15
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Borland does support beginthread(), and their version of the higher control function is called beginthreadNT(). In MS these functions are declared in the process.h header and you have to link with the multithreaded library.

    I think one of my books has a Borland example, (I use MS so am not the best help source here!!!), if I find it, I'll contact you.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Doubt in pointer.
    By shwetha_siddu in forum C Programming
    Replies: 5
    Last Post: 03-21-2009, 02:28 AM
  2. loop to get greatest and least number, its not working please help
    By stressedstudent in forum C++ Programming
    Replies: 27
    Last Post: 09-27-2007, 04:45 AM
  3. Doubt abt Storage!
    By kalamram in forum C Programming
    Replies: 1
    Last Post: 04-21-2006, 06:30 AM
  4. problems with greatest to least sorting
    By Mr_Jack in forum C++ Programming
    Replies: 2
    Last Post: 03-11-2004, 10:12 PM
  5. The Greatest Musician Ever.
    By Cheeze-It in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 06-25-2003, 06:20 PM

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