LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-12-2005, 08:56 AM   #1
mrshadow76
LQ Newbie
 
Registered: Oct 2005
Location: Florida
Distribution: Suse 10.0
Posts: 17

Rep: Reputation: 0
gettid() and threading...


Edited to add:
C++, GCC 3.4.1, MDK 10.1.
------------------------------------------

I have created a function like:

#include <sys/types.h>
#include <linux/unistd.h>

_syscall0( pid_t, gettid )

int myGetTID( void )
{
return gettid();
}


This won't work correctly because where ever the _syscall0( pid_t, gettid) is called, it appears to create a static function gettid() that returns the pid_t of the "thread" it was called in. So, if I statically declare this in a header file, inlined, it will always return the PID of the parent process/first thread.

I can probably make a macro, and inline it all, but I was wondering if there is any "magic" I could use to put this in one area (besides a macro) and have it return the correct result.

Last edited by mrshadow76; 10-12-2005 at 08:57 AM.
 
Old 10-17-2005, 12:02 PM   #2
mrshadow76
LQ Newbie
 
Registered: Oct 2005
Location: Florida
Distribution: Suse 10.0
Posts: 17

Original Poster
Rep: Reputation: 0
Found a better way, that is to create a class within the class you're debugging:

class ThreadDebug
{
public:
int _thread_id;
ThreadDebug( _thread_id = gettid(); );
private:
_syscall0( pid_t, gettid)
};

ThreadDebug _thread_info


_thread_info->_thread_id // Yes, not object oriented, but I had problems with doing a call back function in a multi-threaded environment and trying to use cout
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Python threading? Kedelfor Programming 2 10-25-2005 02:35 PM
Threading JanusPaul Programming 2 02-09-2005 03:39 PM
how to do threading in linux? shrike_912 Programming 2 11-04-2004 09:45 PM
mutt threading sanjiv Linux - Software 0 07-25-2004 05:00 PM
threading using kde penny21 Programming 6 03-09-2004 04:25 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration