Thread: Threading and joining

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    222

    Threading and joining

    hi,


    i have this strange (to me) problem. I have a function in which i make the following function calls:


    Code:
        vector<Tint> segments = bounds(static_cast<Tint>(thr),static_cast<Tint>(vec.size()+1));
    cerr << segments << endl;
    /* Launch threads */
           for (Tint i = 0; i < thr; ++i)
              threads.push_back(thread(MakeGraph<Tint, Tfa, Tbobj>, ref(Ses), segments[i], segments[i+1]-1, static_cast<Tint>(vec.size()), ref(parent), ref(child), ref(Obj)));
    /* Join the threads with the main thread */
    cerr << "Joining\n";
           for(auto &t : threads)
              t.join();
    cerr << "Done\n";
    as a result i get:


    Code:
    0
    785
    1656
    2644
    3816
    5344
    9032
    
    Joining
    Segmentation fault
    so before joining my program breaks. if i use only 1 thre4ad it works ok. I need the program to be able to run several threads in parallel. Is there some obvious reason why thi fails (because one of the potential problems could be in ref(Obj) but i wish to eliminate trivialities first)

    does anyone see and obvious problems? is there something i might be forgetting during the compilation ?

    thnx

  2. #2
    Tweaking master Aslaville's Avatar
    Join Date
    Sep 2012
    Location
    Rogueport
    Posts
    528
    does anyone see and obvious problems? is there something i might be forgetting during the compilation ?
    Did you try attaching a debugger to get the exact point at which the code faults ?

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    your segfault can be in any thread you are joining and not in this code
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. joining codes
    By smk3000 in forum C Programming
    Replies: 5
    Last Post: 12-09-2012, 09:31 AM
  2. joining head to tail
    By m37h0d in forum C++ Programming
    Replies: 0
    Last Post: 04-07-2009, 12:47 PM
  3. Joining strings.
    By DaveHope in forum C++ Programming
    Replies: 10
    Last Post: 06-21-2005, 08:15 AM
  4. Strings joining
    By Lord CyKill in forum C++ Programming
    Replies: 1
    Last Post: 04-13-2003, 05:02 AM
  5. Joining arrays?
    By C-Struggler in forum C Programming
    Replies: 3
    Last Post: 04-07-2003, 07:55 PM