You are not logged in.

#1 2013-06-26 19:47:02

MutantJohn
Member
Registered: 2012-12-17
Posts: 95

thread_db.h vs. thread.h?

Hello All,

As many of you may be well-aware of, Arch Linux and C go hand in hand. And today I just found out that there's a new standard of C!

If that seems odd it's because I was a physics major who only took two CS courses and my professor was so old, gnu99 was the fancy new library.

So I can compile gcc fine with -std=c11 but I also saw that C11 introduces much more multithreading support and that to access them, I should use "#include <threads.h>" in my C files.

But when I did this, gcc kept telling me that the file threads.h did not exist. And it was not lying. My /usr/include (which I had no idea actually held the C libraries which makes things make a lot more sense now) does not have a threads.h but instead it has a thread_db.h which allows me to declare "thread_t tid;" in C files with the new standard.

So I have to ask, why is mine a different name? Every online example (the few there are) uses "#include <threads.h>" but I have to use "#include <thread_db.h>". Am I special you guys?

Offline

#2 2013-06-26 19:52:13

jasonwryan
Forum & Wiki Admin
From: .nz
Registered: 2009-05-09
Posts: 18,562
Website

Re: thread_db.h vs. thread.h?

Moving to Programming and Scripting...


Arch + dwm   •   Mercurial repos  •   Github

Registered Linux User #482438

Offline

#3 2013-06-26 20:08:22

MutantJohn
Member
Registered: 2012-12-17
Posts: 95

Re: thread_db.h vs. thread.h?

Lol my bad.

I was just wondering if my C install is different than others because of the different library name. Oddly enough, this is the only library I've ever had issues with.

Offline

#4 2013-06-26 20:42:17

Trilby
Forum Moderator
From: Massachusetts, USA
Registered: 2011-11-29
Posts: 13,699
Website

Re: thread_db.h vs. thread.h?

/usr/include does not hold libraries, it holds header files which can be included.  Libraries are in /usr/lib.  Crazy naming huh? wink

Your header file names match mine.  I don't know much about multithreading - I use it when I need to, but my background may come from ages well before this professor you speak of (Not that I'm old, just out of touch).  But I usually use pthread.h (posix thread).

If you want to look for a threads.h, try `pkgfile threads.h`

Also, look *in* header files.  Many that have similar names just end up sharing a "heritage" anyway.  I just checked, and thread_db.h includes pthread.h.  So thread_db *might* be some wrapper library for pthread (which make me more confident in just using pthread - I like wrappers on my candy, not on my libraries).

Also, reading the comments at the start of thread_db.h would tell you that it is a thread debugging library - for debugging pthread programs (which is a pain!). So thread_db is not what you want if you just want to *use* threading.

EDIT: after investigating I have to wonder if you are really looking at C examples ... or at C++ examples.  Threads.h is a header file in glibmm which is the C++ API for glib.

EDIT again: I imagine thread_db.h is working for you because the example code you are using is for posix threads, which is included from thread_db.h.  Are the functions you're using all look like pthread_*

Last edited by Trilby (2013-06-26 20:54:28)


InterrobangSlider
• How's my coding? See this page.
• How's my moderating? Feel free to email any concerns, complaints, or objections.

Offline

#5 2013-06-26 21:00:57

MutantJohn
Member
Registered: 2012-12-17
Posts: 95

Re: thread_db.h vs. thread.h?

Lol the library has the line "typedef pthread_t thread_t"

I think I got trolled or am incredibly dumb T_T

Edit: And I think you're right, I might be doing this for C++ code lol. I'm dumb.

Last edited by MutantJohn (2013-06-26 21:01:52)

Offline

#6 2013-06-26 21:01:48

progandy
Member
Registered: 2012-05-17
Posts: 2,146

Re: thread_db.h vs. thread.h?

glibc / gcc does not provides a complete c11 implementation yet.
http://gcc.gnu.org/projects/cxx0x.html
http://gcc.gnu.org/onlinedocs/libstdc++ … s.iso.200x

Last edited by progandy (2013-06-26 21:05:50)

Offline

#7 2013-06-26 21:03:46

Trilby
Forum Moderator
From: Massachusetts, USA
Registered: 2011-11-29
Posts: 13,699
Website

Re: thread_db.h vs. thread.h?

MutantJohn wrote:

I'm dumb.

Nah, just new to multithreaded programming.  You want to see dumb, check out threads that end in the dustbin.  This is a useful thread with a good question.

Last edited by Trilby (2013-06-26 21:03:59)


InterrobangSlider
• How's my coding? See this page.
• How's my moderating? Feel free to email any concerns, complaints, or objections.

Offline

#8 2013-06-26 21:04:29

Old user, new ID
Member
Registered: 2012-09-18
Posts: 13

Re: thread_db.h vs. thread.h?

From http://gcc.gnu.org/onlinedocs/gcc/Standards.html

A fourth version of the C standard, known as C11, was published in 2011 as ISO/IEC 9899:2011. GCC has limited incomplete support for parts of this standard, enabled with -std=c11 or -std=iso9899:2011. (While in development, drafts of this standard version were referred to as C1X.)

Offline

#9 2013-06-26 21:23:25

MutantJohn
Member
Registered: 2012-12-17
Posts: 95

Re: thread_db.h vs. thread.h?

Okay, so there's just no thread.h yet?

That's lame! I want to be the most current now!

And ty for the support <3

Offline

Board footer

Powered by FluxBB