Multithreading in ANSI C (c89/c99/c1x).

Hi guys, I use FreeBSD OS and the C programming language (just C - not C++). I need to create a few threads in my C program. But I don't know how.

Some time ago, I worked in Windows and used Borlan Builder Compilator (used just C++ - not C). But I don't like Windows, C++ and now I using just ANSI C and FreeBSD, and I have many questions.

Okay, one year ago the world was shocked standardization C11 (ISO/IEC 9899:2011). This standard has header files: threads.h
and some functions:
call_once()
cnd_broadcast()
cnd_destroy()
cnd_int()
cnd_signal

... and others

It is very good. But a little problem - where to get the compiler? In FreeBSD ports I found lang/gcc47. Installed it and read man:
Code:
-std=
   Determine the language standard.   This option is currently
   only supported when compiling C or C++.
....
   c11
   c1x
   iso9899:2011
   ISO C11, the 2011 revision of the ISO C standard.  Support
   is incomplete and experimental.  The name c1x is deprecated.

So, I see: "Support is incomplete and experimental. " - it is bad :(


Okay, I think that I can use c99 standard for my idea. But how? I found the "POSIX Thread library" - what do you think, that is a good idea? What is your recommendation for me? How do you deal with multithreading? Show me examples, please, or say what I should have read?

Cry: Help me guys, thank you all!
 
It's POSIX threads for you

You'll want POSIX threads, see pthread(3). There are tutorials (some good, some not quite so good) to be found all over the Web and plenty of books have been written on the subject as well. A word of warning: the actual programming isn't that difficult, but designing distributed algorithms correctly can be quite a challenge sometimes :stud

Hope this helps,

Fonz

P.S. If you can give me some time to retrieve it, I might have some example code for you somewhere. (edit: PM sent)

P.P.S. There is no multithreading intrinsically built into C (be it C89, C99 or whatever). In the UNIX world pthreads is the standard, but as far as I'm aware it isn't portable to e.g. Windows, just like e.g. (n)curses isn't that portable either. In the end, multithreading is OS specific. I have even discovered (subtle) incompatibilities between the pthreads implementations of FreeBSD and Linux.
 
Fonz, thank you, thank you very much! Me helped your answer - now I know that is Google :D (sorry, just joke, sorry me) :D
Thank you fonz, it's really useful information!
 
Back
Top