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.

Chris Seymour
  • 83,387
  • 30
  • 160
  • 202
  • 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 Nov 22 '12 at 17:43
  • I need to do that latter. I'm doing it for a college course as my final project. –  Nov 22 '12 at 17:49
  • is this cross-platform or for a single platform? What are you allowed to use? – Nicu Tofan Nov 22 '12 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. –  Nov 22 '12 at 17:54
  • The Solaris 2.5 Threads Library - http://www.cs.brown.edu/research/thmon/thmon2.html – Nicu Tofan Nov 22 '12 at 17:57

4 Answers4

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.

Hristo Iliev
  • 72,659
  • 12
  • 135
  • 186
  • 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. –  Nov 22 '12 at 17:48
  • It is not apparent from your question. – Hristo Iliev Nov 22 '12 at 17:53
1

POSIX threads is what you're looking for

Ege Akpinar
  • 3,266
  • 1
  • 23
  • 29
  • 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. –  Nov 22 '12 at 17:45
  • 1
    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. – Ege Akpinar Nov 22 '12 at 17:48
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?

Community
  • 1
  • 1
Deepankar Bajpeyi
  • 5,661
  • 11
  • 44
  • 64
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.

user1802174
  • 273
  • 3
  • 10
  • C 2011 includes new headers `` and `` 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. – Jonathan Leffler Nov 22 '12 at 19:14
  • @JonathanLeffler read my reply again, I'm talking about what C++ was before C++ 11, I'm not including c++11 in my scenario. – user1802174 Nov 22 '12 at 19:48
  • 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. – Jonathan Leffler Nov 22 '12 at 19:51
  • @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. – user1802174 Nov 22 '12 at 19:56
  • 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. – Jonathan Leffler Nov 22 '12 at 20:01
  • @JonathanLeffler ok, this can be something that needs to be emphasized. – user1802174 Nov 22 '12 at 20:04