1

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.

5
  • 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. Commented Nov 22, 2012 at 17:43
  • I need to do that latter. I'm doing it for a college course as my final project. Commented Nov 22, 2012 at 17:49
  • is this cross-platform or for a single platform? What are you allowed to use? Commented 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. Commented Nov 22, 2012 at 17:54
  • The Solaris 2.5 Threads Library - cs.brown.edu/research/thmon/thmon2.html Commented Nov 22, 2012 at 17:57

4 Answers 4

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I don't see how this would help me out if technically pthreads is what I'm trying to program. I like don't know how to go about it or where to start is what I'm saying I guess.
It is not apparent from your question.
1

POSIX threads is what you're looking for

2 Comments

I don't see how this would help me out if technically pthreads is what I'm trying to program. I like don't know how to go about it or where to start is what I'm saying I guess.
I'd assumed you'd be able to use POSIX threads to implement your methods. If that's not an option, you could investigate how they're implemented by POSIX threads and try to clone what they do. As for resources for investigating, I don't know any.
1

See the linux clone() system call :

http://en.wikipedia.org/wiki/Clone_(Linux_system_call)

Also this might help :

Source code of PThread Library?

Comments

0

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

C 2011 includes new headers <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.
@JonathanLeffler read my reply again, I'm talking about what C++ was before C++ 11, I'm not including c++11 in my scenario.
Your answer starts "AFAIK, C doesn't have a threading model included in the standard". I'm pointing out to you and anyone who reads your answer that the C2011 standard does include a threading model.
@JonathanLeffler "C++ includes a threading model as standard only in the C++11 version" just right after what you just read. By the way i can appreciate your effort in giving details about the headers, but i think that this informations can be easily extracted from my response.
There is a C 2011 standard and a C++ 2011 standard. I'm not disputing that C++ 2011 includes threading; it certainly does, and it is mostly consistent with the threading included in C 2011. You appear to be under some illusion about what the first clause of your first sentence says. To a native English speaker, it clearly states "The C standard does not cover threading", which is incorrect; the current (2011) C standard does include threading.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.