Sponsored Content
Top Forums UNIX for Advanced & Expert Users Linkage of POSIX threads function calls Post 302501461 by jsimsa on Thursday 3rd of March 2011 03:07:26 PM
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
 

9 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

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

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

7. 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

8. 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

9. 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
threads(5)						Standards, Environments, and Macros						threads(5)

NAME
threads, pthreads - POSIX pthreads and Solaris threads concepts SYNOPSIS
POSIX cc -mt [ flag... ] file... -lpthread [ -lrt library... ] #include <pthread.h> Solaris cc -mt [ flag... ] file... [ library... ] #include <sched.h> #include <thread.h> DESCRIPTION
POSIX and Solaris threads each have their own implementation of the threads library. The libpthread library is associated with POSIX; the libthread library is associated with Solaris. Both implementations are interoperable, their functionality similar, and can be used within the same application. Only POSIX threads are guaranteed to be fully portable to other POSIX-compliant environments. POSIX and Solaris threads require different source, include files and linking libraries. See SYNOPSIS. Similarities Most of the functions in the libpthread and libthread, libraries have a counterpart in the other corresponding library. POSIX function names, with the exception of the semaphore names, have a "pthread" prefix. Function names for similar POSIX and Solaris have similar end- ings. Typically, similar POSIX and Solaris functions have the same number and use of arguments. Differences POSIX pthreads and Solaris threads differ in the following ways: o POSIX threads are more portable. o POSIX threads establish characteristics for each thread according to configurable attribute objects. o POSIX pthreads implement thread cancellation. o POSIX pthreads enforce scheduling algorithms. o POSIX pthreads allow for clean-up handlers for fork(2) calls. o Solaris threads can be suspended and continued. o Solaris threads implement interprocess robust mutex locks. o Solaris threads implement daemon threads, for whose demise the process does not wait. Function Comparison The following table compares the POSIX pthreads and Solaris threads functions. When a comparable interface is not available either in POSIX pthreads or Solaris threads, a hyphen (-) appears in the column. Functions Related to Creation POSIX (libpthread) Solaris (libthread) pthread_create() thr_create() pthread_attr_init() - pthread_attr_setdetachstate() - pthread_attr_getdetachstate() - pthread_attr_setinheritsched() - pthread_attr_getinheritsched() - pthread_attr_setschedparam() - pthread_attr_getschedparam() - pthread_attr_setschedpolicy() - pthread_attr_getschedpolicy() - pthread_attr_setscope() - pthread_attr_getscope() - pthread_attr_setstackaddr() - pthread_attr_getstackaddr() - pthread_attr_setstacksize() - pthread_attr_getstacksize() - pthread_attr_getguardsize() - pthread_attr_setguardsize() - pthread_attr_destroy() - - thr_min_stack() Functions Related to Exit POSIX (libpthread) Solaris (libthread) pthread_exit() thr_exit() pthread_join() thr_join() pthread_detach() - Functions Related to Thread Specific Data POSIX (libpthread) Solaris (libthread) pthread_key_create() thr_keycreate() pthread_setspecific() thr_setspecific() pthread_getspecific() thr_getspecific() pthread_key_delete() - Functions Related to Signals POSIX (libpthread) Solaris (libthread) pthread_sigmask() thr_sigsetmask() pthread_kill() thr_kill() Functions Related to IDs POSIX (libpthread) Solaris (libthread) pthread_self() thr_self() pthread_equal() - - thr_main() Functions Related to Scheduling POSIX (libpthread) Solaris (libthread) - thr_yield() - thr_suspend() - thr_continue() pthread_setconcurrency() thr_setconcurrency() pthread_getconcurrency() thr_getconcurrency() pthread_setschedparam() thr_setprio() pthread_getschedparam() thr_getprio() Functions Related to Cancellation POSIX (libpthread) Solaris (libthread) pthread_cancel() - pthread_setcancelstate() - pthread_setcanceltype() - pthread_testcancel() - pthread_cleanup_pop() - pthread_cleanup_push() - Functions Related to Mutexes POSIX (libpthread) Solaris (libthread) pthread_mutex_init() mutex_init() pthread_mutexattr_init() - pthread_mutexattr_setpshared() - pthread_mutexattr_getpshared() - pthread_mutexattr_setprotocol() - pthread_mutexattr_getprotocol() - pthread_mutexattr_setprioceiling() - pthread_mutexattr_getprioceiling() - pthread_mutexattr_settype() - pthread_mutexattr_gettype() - pthread_mutexattr_destroy() - pthread_mutex_setprioceiling() - pthread_mutex_getprioceiling() - pthread_mutex_lock() mutex_lock() pthread_mutex_trylock() mutex_trylock() pthread_mutex_unlock() mutex_unlock() pthread_mutex_destroy() mutex_destroy() Functions Related to Condition Variables POSIX (libpthread) Solaris (libthread) pthread_cond_init() cond_init() pthread_condattr_init() - pthread_condattr_setpshared() - pthread_condattr_getpshared() - pthread_condattr_destroy() - pthread_cond_wait() cond_wait() pthread_cond_timedwait() cond_timedwait() pthread_cond_signal() cond_signal() pthread_cond_broadcast() cond_broadcast() pthread_cond_destroy() cond_destroy() Functions Related to Reader/Writer Locking POSIX (libpthread) Solaris (libthread) pthread_rwlock_init() rwlock_init() pthread_rwlock_rdlock() rw_rdlock() pthread_rwlock_tryrdlock() rw_tryrdlock() pthread_rwlock_wrlock() rw_wrlock() pthread_rwlock_trywrlock() rw_trywrlock() pthread_rwlock_unlock() rw_unlock() pthread_rwlock_destroy() rwlock_destroy() pthread_rwlockattr_init() - pthread_rwlockattr_destroy() - pthread_rwlockattr_getpshared() - pthread_rwlockattr_setpshared() - Functions Related to Semaphores POSIX (libpthread) Solaris (libthread) sem_init() sema_init() sem_open() - sem_close() - sem_wait() sema_wait() sem_trywait() sema_trywait() sem_post() sema_post() sem_getvalue() - sem_unlink() - sem_destroy() sema_destroy() Functions Related to fork() Clean Up POSIX (libpthread) Solaris (libthread) pthread_atfork() - Functions Related to Limits POSIX (libpthread) Solaris (libthread) pthread_once() - Functions Related to Debugging POSIX (libpthread) Solaris (libthread) - thr_stksegment() LOCKING
Synchronization POSIX (libpthread) Solaris (libthread) Multi-threaded behavior is asynchronous, and therefore, optimized for concurrent and paral- lel processing. As threads, always from within the same process and sometimes from multiple processes, share global data with each other, they are not guaranteed exclusive access to the shared data at any point in time. Securing mutually exclusive access to shared data requires synchronization among the threads. Both POSIX and Solaris implement four synchronization mechanisms: mutexes, condition vari- ables, reader/writer locking (optimized frequent-read occasional-write mutex), and semaphores. Synchronizing multiple threads diminishes their concurrency. The coarser the grain of synchronization, that is, the larger the block of code that is locked, the lesser the concurrency. MT fork() If a POSIX threads program calls fork(2), it implicitly calls fork1(2), which replicates only the calling thread. Should there be any out- standing mutexes throughout the process, the application should call pthread_atfork(3C) to wait for and acquire those mutexes prior to calling fork(). SCHEDULING
POSIX Scheduling allocation size per thread is greater than one. POSIX supports the following three scheduling policies: SCHED_OTHER Timesharing (TS) scheduling policy. It is based on the timesharing scheduling class. SCHED_FIFO First-In-First-Out (FIFO) scheduling policy. Threads scheduled to this policy, if not pre-empted by a higher priority, will proceed until completion. Threads whose contention scope is system (PTHREAD_SCOPE_SYSTEM) are in real-time (RT) scheduling class. The calling process must have a effective user ID of 0. SCHED_FIFO for threads whose contention scope's process (PTHREAD_SCOPE_PROCESS) is based on the TS scheduling class. SCHED_RR Round-Robin scheduling policy. Threads scheduled to this policy, if not pre-empted by a higher priority, will execute for a time period determined by the system. Threads whose contention scope is system (PTHREAD_SCOPE_SYSTEM) are in real-time (RT) scheduling class and the calling process must have a effective user ID of 0. SCHED_RR for threads whose contention scope is process (PTHREAD_SCOPE_PROCESS) is based on the TS scheduling class. Solaris Only scheduling policy supported is SCHED_OTHER, which is timesharing, based on the TS scheduling class. ERRORS
In a multi-threaded application, linked with libpthread or libthread, EINTR may be returned whenever another thread calls fork(2), which calls fork1(2) instead. To ensure proper library linking order, use this option, rather than -lthread, to link with libthread. USAGE
-mt compiler option The -mt compiler option compiles and links for multithreaded code. It compiles source files with -D_REENTRANT and augments the set of sup- port libraries to include -lthread in the required order. To ensure proper library linking order, use this option rather than -lthread to link with libthread. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe, Fork 1-Safe | +-----------------------------+-----------------------------+ SEE ALSO
crle(1), fork(2), libpthread(3LIB), librt(3LIB), libthread(3LIB), pthread_atfork(3C), pthread_create(3C), attributes(5), standards(5) Linker and Libraries Guide SunOS 5.10 20 Aug 2003 threads(5)
All times are GMT -4. The time now is 01:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy