how to make a program stop indeffinitely?

This is a discussion on how to make a program stop indeffinitely? within the C++ Programming forums, part of the General Programming Boards category; I have a program that spawns off threads that listen for tcp connections & respond to them appropriately. After I ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    72

    how to make a program stop indeffinitely?

    I have a program that spawns off threads that listen for tcp connections & respond to them appropriately. After I create the pthread, the program continues execution to the return, then exits. I've stopped that by putting a simple cin >> some_char; before the final return, but is there a better way to get the program to stop before it returns without requiring any resources... like a sleep(FOREVER) or something similar?

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >but is there a better way to get the program to stop before it returns without requiring any resources...
    Something like abort()?

    -Prelude
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    417
    try this:

    Code:
    for ( ; ; )
    {
            //code goes here
    }
    and then use the line of code "break;" somewhere if you want to get out

  4. #4
    Registered User
    Join Date
    Oct 2002
    Posts
    72
    Something like abort()?
    I don't want it to actually exit - just stop execution

    for( ; ; )
    the problem with that is that because the /* code goes here */ section does nothing but spawn off a thread or two, it will execute as fast as putting something simple like i++ in the body of the for... in other words, it will take 100% of the CPU.

  5. #5
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    What about exit(), it's in the <cstdlib>

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  2. A very long list of questions... maybe to long...
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-16-2007, 05:36 AM
  3. What program to make animated Gifs?
    By KneeGrow in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 01-16-2005, 12:00 PM
  4. Programmer Cannot Make Any Program!
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 05-08-2002, 12:48 PM
  5. How can I make a program wait for an event?
    By DRoss in forum C++ Programming
    Replies: 0
    Last Post: 09-06-2001, 09:28 AM

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