Find the answer to your Linux question:
Results 1 to 5 of 5
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Engineer Javasnob's Avatar
    Join Date
    Jul 2005

    Multithreading in C

    How do you accomplish multithreading in C? Is the only good solution to use fork()?


  2. #2
    Linux User
    Join Date
    Aug 2005


    You can use libpthreads shipped with glibc. You are able to create a multithreading application without using fork, wich double your process.
    When using Windows, have you ever told "Ehi... do your business?"
    Linux user #396597 (

  3. #3
    Linux Enthusiast scientica's Avatar
    Join Date
    Sep 2003
    South- or "Mid-" Sweden
    adter a quick google I found this:
    I'm goona book mark it for now and read it later - at first glance it looks like what you're looking for (at least it's enought for me to get started, and I wouldn't claim to be an über-geek when it comes to writing threaded code in linux (I've only written trheaded code for win32 in assembly sometime ago (in the "dark ages" ) ))
    Regards Scienitca (registered user #335819 - )
    A master is nothing more than a student who knows something of which he can teach to other students.

  4. $spacer_open
  5. #4
    Linux Guru
    Join Date
    Oct 2001
    Täby, Sweden
    Indeed, fork() does not create multiple threads, in the normal sense of the word. It is true that fork does create a new thread, but only as part of an entirely new (although duplicated) process, which means that neither the address space nor the file descriptors will be shared between the two processes.

    While you can use the clone() syscall directly to create threads, that would be rather stupid, since it would require you to manually set up stack spaces and all sorts of things for the new threads. The good (and portable to other Unix systems) way to create threads in Linux is, as burnit said, to use pthreads.

    They used to be documented in glibc's texinfo, but that section seems to be gone now, for some weird reason. Anyway, the manpages still exist. Check the manpages for pthread_create and pthread_mutex_init, and the manpages they refer to in the "SEE ALSO" section.

  6. #5
    Just Joined!
    Join Date
    Oct 2005
    here's my two cents (cuz i have nothing better to do of course ^_^)

    The Linux philosophy towards threads is as such: threads are not meant to be light weight processes, instead they are simply a means in which multiple processes can communicate with each other through shared resources. In the end all the threading libraries end up calling clone() which splits the program in two according to the number of shared resources specified through it's parameters.

    If you'd like your program to be portable then use the p-threads library subroutines for creating threads, but if you don't care about portability then you can look up the clone() system call in the man pages

Posting Permissions

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