Find the answer to your Linux question:
Results 1 to 3 of 3
Hey guys, Im new here, but since I think I've now permanently switched to Linux, I've decided to become a member of these forums. (I think linux is great btw! ...
  1. #1
    Just Joined!
    Join Date
    Sep 2009
    Posts
    5

    Unhappy [SOLVED] c++ threading in linux

    Hey guys, Im new here, but since I think I've now permanently switched to Linux, I've decided to become a member of these forums. (I think linux is great btw! i like the control i have, if i need it, i can change it - its all open source. I run fedora, very nice! very quick!! ^_^)

    Anyways, I have been programming in c++ (in windows :P ) for quite some time, pretty used to OOP and the like. I have tried my hand at making a multi-threaded application. I have wrapped it in a class (I think that's the correct terminology), so that I don't need mutex's which I'm not quite ready to learn yet I think.

    Everything works, exept for some kind of problem with memory management I think. I print some data to screen, but I notice that the more it continues (it does a lot of complex calculations) the more it slows down. Except the calculations involved aren't getting any longer! Well anyways, I've searched the net (and these forums) for a solution to my problem, but I can't find anything. I terminate the POSIX threads (by pthread_join()ing them or using pthread_detach() function), and I use the 'new' command *nowhere* in my code.

    Would anyone know the solution to by problem? I would post the code here but Its over 200 lines, and don't think that would be very good as it probably isnt that easy to follow.

    I used 'top' and 'grep' to get the following results:
    Code:
      PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
     8687 Joshua    20   0 81308  66m  980 R  3.7 13.3   0:00.11 HSC                
     8687 Joshua    20   0  100m  66m  988 R 36.2 13.3   0:01.20 HSC                
     8687 Joshua    20   0  120m  66m  988 R 99.9 13.3   0:05.19 HSC                
     8687 Joshua    20   0  120m  66m  988 R 99.9 13.3   0:08.66 HSC                
     8687 Joshua    20   0  120m  66m  988 R 95.4 13.3   0:11.53 HSC                
     8687 Joshua    20   0  120m  66m  988 R 96.4 13.3   0:14.43 HSC                
     8687 Joshua    20   0  120m  66m  988 R 99.9 13.3   0:17.95 HSC                
     8687 Joshua    20   0  120m  66m  988 R 99.9 13.3   0:21.36 HSC                
     8687 Joshua    20   0  120m  66m  988 R 99.9 13.3   0:24.58 HSC                
     8687 Joshua    20   0  120m  66m  988 R 99.9 13.3   0:27.62 HSC                
     8687 Joshua    20   0  120m  66m  988 R 90.0 13.3   0:30.33 HSC                
     8687 Joshua    20   0  120m  66m  988 R 92.7 13.3   0:33.12 HSC                
     8687 Joshua    20   0  130m  66m  988 R 87.9 13.3   0:35.77 HSC                
     8687 Joshua    20   0  120m  66m  988 R 99.9 13.3   0:38.78 HSC                
     8687 Joshua    20   0  120m  66m  988 R 99.9 13.3   0:41.94 HSC                
     8687 Joshua    20   0  120m  66m  988 R 99.9 13.3   0:45.12 HSC
    It uses almost all my CPU (expected as it does a lot of calculations) but it doesnt use that much RAM. I think firefox and the X application both use more than 120m (on my system). I would think if I had a memory leak then the 'top' command would show continuously increasing memory usage??

    Anyone able to help me out/suggest things to try?

  2. #2
    Just Joined!
    Join Date
    Sep 2009
    Posts
    5
    oh.... damn... i found the solution... i feel like such a noob :S i hadnt cleared out a variable and it ended up getting bigger and bigger.... any way of deleting my thread? </embarrassment>

  3. #3
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Just close it.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...