Linkage of POSIX threads function calls


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Linkage of POSIX threads function calls
# 1  
Old 03-03-2011
Linkage of POSIX threads function calls

I wonder if someone knows what is the rationale behind linking function calls of the POSIX threads library at link-time vs. run-time.

For example, if I create the following program:

Code:
#include <pthread.h>

void noop() {
  return;
}

int main() {
  pthread_self();
  pthread_atfork(noop, noop, noop);
  return 0;
}

and compile it on Ubuntu version 10.10 with gcc version 4.4.5 using:

Code:
gcc -o test -lpthread -pthread test.c

then the pthread_self symbol is linked (dynamically) at run-time, while the pthread_atfork symbol is linked (statically) at link-time.

Further, there is the case of pthread_equal, code of which might be inlined (assuming __USE_EXTERN_INLINES is defined).

My project plans to use a run-time interposition based wrapper for the POSIX threads library functions to monitor and control interaction of a program with the pthreads library. Cases such as pthread_atfork and pthread_equal are giving me a headache :-).

--Jiri

Last edited by pludi; 03-03-2011 at 04:33 PM.. Reason: please use code tags
# 2  
Old 03-03-2011
It's extremely difficult to track down how nptl works internally sometimes. It's full of pointless-looking stubs like
Code:
void pthread_function_thing(...) { return(___internal_pthread_function_thing(...)); }

and they'd never ever put the ___internal junk in the same file, that would be far too easy.

But if I had to guess, it's a way to get at your program's internal symbols in a way a mere shared library wouldn't be able to. Adding a callback to fork() can't have been easy.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Question about Function calls

Hello everyone, here's my problem: I want to create two shell scripts. one of them should includes some functions, the other one just the function calls. Is this possible? Can i call a function which is placed in a scriptfile eg functions.sh out of another script eg call.sh? :confused: And if... (2 Replies)
Discussion started by: Sebi0815
2 Replies

2. Programming

need help with posix threads

Hi, I am new to posix threads. The no of threads to be created depends on the runtime. If I get the number of threads, I need to forward declare pthread_t mythread; how to do that can I use pointers and use malloc()?? I also have another question. The pthread_join is used to make... (0 Replies)
Discussion started by: brett01
0 Replies

3. UNIX for Advanced & Expert Users

Posix threads

Hi, consider the code below: #include <stdio.h> . . struct myStruct { char *message ; int id; }; . . . void *thread_function( void *ptr ); nt main() { pthread_t thread1, thread2 ,thread3 ; struct myStruct nico1; (2 Replies)
Discussion started by: Behnaz
2 Replies

4. Programming

ndd commands using function calls

Hi, Is there any function calls available ( for using in a C program ) to get the Ethernet Link status. ? I am looking for the status available from ndd /dev/hme link_status And how about plumbing and configuring an interface using C program ? BTW, Is all this documented... (3 Replies)
Discussion started by: shibz
3 Replies

5. Programming

POSIX threads and data safety

I created multiple POSIX threads (on readhat Linux) in a C program in my app. What I am doing is - I am creating threads equal to the number of CPUs in the system and and equal number of instances of a certain data structure, basically a queue implementation. I am assigning one ID to the thread... (2 Replies)
Discussion started by: radiatejava
2 Replies

6. Programming

Tracing Function Calls in a program

Apart from writing debug and statements in constructors is there any way by which we can trace the function call stack at any depth? The issue that we always face is that when program crashes (Web Server running on Linux) we have no idea where it crashes and we have to do the hard way of... (1 Reply)
Discussion started by: uunniixx
1 Replies

7. HP-UX

ERROR: more than one instance of overloaded function "vprintf" has "C" linkage

Hi people! I've got this own library: -------------------------------------------- Personal.h -------------------------------------------- #ifdef __cplusplus extern "C" { #endif #include <stdio.h> #include <stdarg.h> #include <string.h> ... (0 Replies)
Discussion started by: donatoll
0 Replies

8. Programming

POSIX threads

Hello ! Let's supose I have a main function in C , and two POSIX threads. I give you an example down : int main() { int something; char else; void *FirstThread(); void *SecondThread(); .. <start those two pthreads ..> return 0;} void *FirstThread() { ... } void *SecondThread()... (2 Replies)
Discussion started by: !_30
2 Replies

9. AIX

overriding function calls without recompiling

i want to replace the *alloc and free function calls in an existing project with my own functions, to be able to log the adresses etc in a text file. (memoryleak debugging) I think LD_PRELOAD is what i am looking for. That way i could create a Library with my own malloc functions and link them... (1 Reply)
Discussion started by: Lazzar
1 Replies
Login or Register to Ask a Question