Thread: multithreading

  1. #1
    Registered User
    Join Date
    Jun 2003
    Location
    Austria
    Posts
    55

    multithreading

    hi everybody.

    im playing around with the clone() syscall to implement multithreading. My problem now is, that every time i try to clone() a thread out of another clone()d thread the program crashes with an segmentation fault.
    You got an idea why? I really need the feature to create an thread out of another.. but it seems, that clone() is the wrong way

    ice

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Post a small example code which crashes perhaps.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Try using POSIX threads instead of clone(). look at pthread_create(). Granted, you should still be able to use clone() for multithreading (I think some implementations of pthread_create() use clone()), but using the POSIX methods might make you life a little easier.

  4. #4
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    Quote Originally Posted by bithub
    Try using POSIX threads instead of clone(). look at pthread_create(). Granted, you should still be able to use clone() for multithreading (I think some implementations of pthread_create() use clone()), but using the POSIX methods might make you life a little easier.
    All implementations of pthread_create() must use some form of clone() later on, the linux kernel can not handle threads. All threads are in linux are just "lightweight processes".
    Help populate a c/c++ help irc channel
    server: irc://irc.efnet.net
    channel: #c

  5. #5
    Registered User
    Join Date
    Jun 2003
    Location
    Austria
    Posts
    55
    thank you for the replys.
    i already used the posix threads one day after my first post. So i have no more problems with multithreading.

    But i'm still interestet in the fac, why the 2. clone call was crashing. i'll search the example code and post it.. just give me some time
    But i think its my fault, because as i read the pthread_create function just uses the clone system call..

    ice
    Last edited by IceBall; 09-20-2004 at 11:24 PM.

  6. #6
    Registered User
    Join Date
    Jun 2003
    Location
    Austria
    Posts
    55
    hmm cant find the code.. but it looked like this:

    int thread2() {..}

    int thread1() { clone(..., thread2,...);...}

    int main() {clone(..., thread1,...); ...}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multithreading (flag stopping a thread, ring buffer) volatile
    By ShwangShwing in forum C Programming
    Replies: 3
    Last Post: 05-19-2009, 07:27 AM
  2. multithreading in C++
    By manzoor in forum C++ Programming
    Replies: 19
    Last Post: 11-28-2008, 12:20 PM
  3. Question on Multithreading
    By ronan_40060 in forum C Programming
    Replies: 1
    Last Post: 08-23-2006, 07:58 AM
  4. Client/Server and Multithreading
    By osal in forum Windows Programming
    Replies: 2
    Last Post: 07-17-2004, 03:53 AM
  5. Multithreading
    By JaWiB in forum Game Programming
    Replies: 7
    Last Post: 08-24-2003, 09:28 PM