Take the 2-minute tour ×

I have used fork() in C to start another process. How do I start a new thread?

share|improve this question
It depends on the platform. Here's how to do it on Windows: http://msdn.microsoft.com/en-us/library/ms682453.aspx –  Eric Z Beard Sep 11 '08 at 15:08
As explained in the CreateThread documentation you linked to, if the program uses the C runtime library, _beginthreadex should be used, not CreateThread. –  ChrisN Sep 11 '08 at 15:24
Thanks, I hadn't noticed that. How do you know if you're using the CRT? I thought everything used it. –  Eric Z Beard Sep 11 '08 at 16:19
You can tell the compiler to not include the default libraries. Then you cannot use the CRT by accident and you can use the Win32 functions entirely. –  Zan Lynx Apr 6 '10 at 3:59

5 Answers 5

up vote 39 down vote accepted

Since you mentioned fork() I assume you're on a Unix-like system, in which case POSIX threads (usually referred to as pthreads) are what you want to use.

Specifically, pthread_create() is the function you need to create a new thread. Its arguments are:

int  pthread_create(pthread_t  *  thread, pthread_attr_t * attr, void *

The first argument is the returned pointer to the thread id. The second argument is the thread arguments, which can be NULL unless you want to start the thread with a specific priority. The third argument is the function executed by the thread. The fourth argument is the single argument passed to the thread function when it is executed.

share|improve this answer
Here's an example on how to use it: timmurphy.org/2010/05/04/… –  tremendows Jul 18 '13 at 11:25
Do POSIX threads not count as "plain C" now that the C11 standard defines them? –  Hydronium Oct 6 '13 at 18:50
While the C11 multithreading API is heavily influenced by POSIX threads, they are not identical. So it doesn't strike me as right to say that POSIX threads are "plain C". –  Ben Ylvisaker Sep 27 at 20:49

AFAIK, ANSI C doesn't define threading, but there are various libraries available.

If you are running on Windows, link to msvcrt and use _beginthread or _beginthreadex.

If you are running on other platforms, check out the pthreads library (I'm sure there are others as well).

share|improve this answer

pthreads is a good start, look here

share|improve this answer

Threads are not part of the C standard, so the only way to use threads is to use some library (eg: POSIX threads in Unix/Linux, _beginthread/_beginthreadex if you want to use the C-runtime from that thread or just CreateThread Win32 API)

share|improve this answer

Check out the pthread (POSIX thread) library.

share|improve this answer

Your Answer


