threads and memory issue

This is a discussion on threads and memory issue within the C Programming forums, part of the General Programming Boards category; i m using four threads in a c program.each thread runs in an infinite while loop but that leads to ...

  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    3

    threads and memory issue

    i m using four threads in a c program.each thread runs in an infinite while loop but that leads to nearly 95% cpu usage.The program requirement forbids me to use sleep to pause a thread.All the threads need to run continuously.....do i have any other alternative to using infinte while loop...

  2. #2
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,236
    What your program is going to do? What platform?
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  3. #3
    Registered User
    Join Date
    Jul 2006
    Posts
    3
    Actually its doing some calculation in each thread.....using a few array and global variables...its on linux...

  4. #4
    Just kidding.... fnoyan's Avatar
    Join Date
    Jun 2003
    Location
    Still in the egg
    Posts
    269
    Have your heard about semaphores or synchronization? if not just make a search! I think these are the concepts you are looking for!

    Using while(1) loops (I think this is waht you did) is a performance penalty!

  5. #5
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,236
    If your program has to do some heavy calculations, 95% CPU usage is natural. I concluded that your threads should run in parallel and are independent.
    Last edited by siavoshkc; 07-22-2006 at 11:35 AM.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  6. #6
    Registered User
    Join Date
    Jul 2006
    Posts
    3
    Using the sleep thing also didnt help me.....the cpu usage still exceeds 95%....do i have another alternative to using while(1)....

  7. #7
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,236
    What your program is supposed to do?
    Why you want it to use less CPU power?
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. POSIX Threads and dynamic memory allocation
    By PING in forum Linux Programming
    Replies: 1
    Last Post: 04-02-2009, 11:28 AM
  2. Is this code memory leak free? ---> POSIX Threads
    By avalanche333 in forum C++ Programming
    Replies: 9
    Last Post: 04-13-2007, 04:19 PM
  3. problem with win32 threads
    By pdmarshall in forum C++ Programming
    Replies: 6
    Last Post: 07-29-2004, 03:39 PM
  4. threads not releasing memory?
    By Spark in forum C Programming
    Replies: 3
    Last Post: 06-08-2002, 03:09 PM

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