2002-01-23 01:23:10 +00:00
|
|
|
#define __USE_GNU /* non-posix functions */
|
2002-01-22 21:41:14 +00:00
|
|
|
#include <pthread.h>
|
2002-01-23 01:23:10 +00:00
|
|
|
#undef __USE_GNU
|
2002-01-22 21:41:14 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2002-01-23 01:23:10 +00:00
|
|
|
// the thread_self algorithm:
|
|
|
|
/*
|
2002-01-22 21:41:14 +00:00
|
|
|
char * sp = CURRENT_STACK_FRAME;
|
|
|
|
int self = (int) pthread_self();
|
|
|
|
|
|
|
|
if (self % PTHREAD_THREADS_MAX < 2)
|
2002-01-23 01:23:10 +00:00
|
|
|
* we only support the main thread, not the manager. *
|
2002-01-22 21:41:14 +00:00
|
|
|
return &__pthread_initial_thread;
|
|
|
|
|
|
|
|
#ifdef _STACK_GROWS_DOWN
|
|
|
|
return (pthread_descr)(((unsigned long)sp | (STACK_SIZE-1))+1) - 1;
|
|
|
|
#else
|
|
|
|
return (pthread_descr)((unsigned long)sp &~ (STACK_SIZE-1));
|
|
|
|
#endif
|
2002-01-23 01:23:10 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
static _pthread_descr linuxthreads_self()
|
|
|
|
{
|
|
|
|
pthread_mutexattr_t mutexattr;
|
|
|
|
pthread_mutex_t mutex;
|
|
|
|
_pthread_descr self;
|
|
|
|
|
|
|
|
pthread_mutexattr_init (&mutexattr);
|
|
|
|
pthread_mutexattr_setkind_np (&mutexattr, PTHREAD_MUTEX_ERRORCHECK_NP);
|
|
|
|
pthread_mutex_init (&mutex, &mutexattr);
|
|
|
|
|
|
|
|
pthread_mutex_lock (&mutex);
|
|
|
|
self = mutex.__m_owner;
|
|
|
|
pthread_mutex_unlock (&mutex);
|
|
|
|
|
|
|
|
printf ("pthread_self: %d\n", pthread_self());
|
|
|
|
printf ("descr: %p\n", self);
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *pthread (void *unused)
|
|
|
|
{
|
|
|
|
linuxthreads_self();
|
|
|
|
return NULL;
|
2002-01-22 21:41:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main (int argc, char *argv[])
|
|
|
|
{
|
2002-01-23 01:23:10 +00:00
|
|
|
pthread_t tid;
|
|
|
|
|
|
|
|
pthread_create (&tid, NULL, pthread, NULL);
|
|
|
|
pthread_join (tid, NULL);
|
|
|
|
|
|
|
|
linuxthreads_self();
|
|
|
|
exit (0);
|
2002-01-22 21:41:14 +00:00
|
|
|
}
|