Thread: clone problems

  1. #16
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    segmentation fault
    Quote Originally Posted by The-Forgotten View Post
    And I have another question, how to know how much space my child stack will need? You allocated 8192, I know that this is 2¹³, but why not 2¹⁴ or 2¹²?
    There's an important point in here. For the first one, I just figured 8 KB was enough. In the second one, there was some corruption present so I added a few zeros and that resolved it.

    The default stack size on linux is actually 8 MB, but you can get away with setting this much lower (even, 512 KB), so your stacks should really be something more comparable. Which brings me to the important point -- they shouldn't be taken from main's stack. They should more properly be malloc'd on the heap.

    On the topic of stacks, I'm sure that your counting problem in the synchronized version is due to fact that the data in both stacks is identical except for the value of an internal counter (eg, with my code, it would be the "i"), so you have developed your code working from the empirical results of that (because you only actually have one stack, and thread A's local variables are actually also thread B's local variables).

    Like I said, think logically about how your count accumulates (and hopefully, check with your prof about posting your code specifically on this forum! Life is much easier that way, less need for guessing).
    Last edited by MK27; 12-04-2011 at 03:17 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  2. #17
    Registered User
    Join Date
    Nov 2011
    Karlsruhe, Germany
    Hi, everything worked fine and I wanted you to know, you were right, CLONE_THREAD was not required, but he admitted that this information was missing in the assignment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Clone function
    By gustavosserra in forum C++ Programming
    Replies: 6
    Last Post: 01-03-2004, 05:57 PM
  2. my breakout clone
    By lambs4 in forum Game Programming
    Replies: 12
    Last Post: 09-03-2003, 02:16 PM
  3. AGS Tetris Clone
    By Damascus in forum Game Programming
    Replies: 1
    Last Post: 03-07-2003, 05:17 PM
  4. First Human clone
    By Commander in forum A Brief History of
    Replies: 56
    Last Post: 12-30-2002, 04:46 PM