I'm working on a project where I have to program a multithreaded library in C. I have to write functions such as thread_t_init, thread_t_shutdown, thread_t_create, thread_t_terminate, thread_t_yield. I'm looking to find a good place to start or at least some advice. Anything would help whether it's a certain website or even just a conversation.
-
Are you writing a library that uses threads to accomplish some task? Or a library that provides threading capabilities for other programs to utilize? If the former, you don't need to write functions for creating and terminating threads; some other library like pthreads provides those. If the latter, you're reinventing the wheel.Wyzard– Wyzard2012-11-22 17:43:59 +00:00Commented Nov 22, 2012 at 17:43
-
I need to do that latter. I'm doing it for a college course as my final project.user1642463– user16424632012-11-22 17:49:40 +00:00Commented Nov 22, 2012 at 17:49
-
is this cross-platform or for a single platform? What are you allowed to use?Nicu Tofan– Nicu Tofan2012-11-22 17:51:40 +00:00Commented Nov 22, 2012 at 17:51
-
It's for a solaris system and it's supposed to be a user-level thread library. I'm allowed to use anything but pthreads from what I know.user1642463– user16424632012-11-22 17:54:44 +00:00Commented Nov 22, 2012 at 17:54
-
The Solaris 2.5 Threads Library - cs.brown.edu/research/thmon/thmon2.htmlNicu Tofan– Nicu Tofan2012-11-22 17:57:59 +00:00Commented Nov 22, 2012 at 17:57
4 Answers
Under Unix systems, the dominant threading API is POSIX Threads, also known as Pthreads. It is a standard set of API calls that each Unix vendor has to implement. Virtually all Unix derivates and Unix-like OSes, including Linux, Solaris, *BSD and others (since you haven't specified which one exactly) provide implementations of this API. Threaded programs written with Pthreads are fairly portable among the different Unices.
Lawrence Livermore National Laboratory provide an excellent set of tutorials on different parallel programming techniques, including one on Pthreads.
2 Comments
POSIX threads is what you're looking for
2 Comments
See the linux clone() system call :
http://en.wikipedia.org/wiki/Clone_(Linux_system_call)
Also this might help :
Comments
As far as i know C doesn't have a threading model included in the standard, C++ includes a threading model as standard only in the C++11 version. As consequence programming with threads is the same thing as using an external library, like with the C++ pre-C++11, you need to master the library that you decide to pick, under Unix the Pthreads (POSIX threads) library is the de-facto standard.
Look for resources about Pthreads.
6 Comments
<stdatomic.h> and <threads.h> which are largely aligned with the threads in C++ 2011. So your information is a little out of date — but you're unlikely to be alone in your unawareness of the new material in C 2011.