mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-23 16:50:47 +00:00
added a test for pth and pthreads. in summary, it doesn't work because in __pthread_find_self() some funny stack poin...
Original commit message from CVS: added a test for pth and pthreads. in summary, it doesn't work because in __pthread_find_self() some funny stack pointer math is done that will result in no matches for __pthread_find_self(). this is dereferenced in __errno_location, causing a segfault on context switch because of the errno-swapping on the part of pth. it's a mess and i don't know how to get around it. i'll have to look into what ngpt does for looking up errno, as it has kernel threads as well as user threads.
This commit is contained in:
parent
1bc541f213
commit
d48d5c640a
3 changed files with 88 additions and 2 deletions
|
@ -31,9 +31,10 @@ noinst_LTLIBRARIES = libpth-mctx.la
|
|||
|
||||
libpth_mctx_la_SOURCES = pth_mctx.c pth_p.h pth_vers.c pth.h pth_acdef.h pth_acmac.h
|
||||
|
||||
noinst_PROGRAMS = test-pth
|
||||
noinst_PROGRAMS = test-pth test-pth-pthreads
|
||||
|
||||
test_pth_LDADD = libpth-mctx.la
|
||||
test_pth_pthreads_LDADD = libpth-mctx.la -lpthread
|
||||
|
||||
#pth_mctx_a_DEPENDENCIES = shtool
|
||||
|
||||
|
|
|
@ -52,8 +52,8 @@
|
|||
#undef PTH_MCTX_STK_use
|
||||
#undef PTH_STACKGROWTH
|
||||
#undef PTH_DMALLOC
|
||||
#undef PTH_NEED_SEPARATE_REGISTER_STACK
|
||||
|
||||
@BOTTOM@
|
||||
|
||||
#endif /* _PTH_ACDEF_H_ */
|
||||
|
||||
|
|
85
gst/cothreads/test-pth-pthreads.c
Normal file
85
gst/cothreads/test-pth-pthreads.c
Normal file
|
@ -0,0 +1,85 @@
|
|||
#include "pth_p.h"
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#ifndef CURRENT_STACK_FRAME
|
||||
#define CURRENT_STACK_FRAME ({ char __csf; &__csf; })
|
||||
#endif /* CURRENT_STACK_FRAME */
|
||||
|
||||
pth_mctx_t main_context;
|
||||
int threadnum = 0;
|
||||
/*
|
||||
int *__errno_location()
|
||||
{
|
||||
static pth_mctx_t ctx;
|
||||
|
||||
errno_shield {
|
||||
pth_mctx_save (&ctx);
|
||||
}
|
||||
|
||||
return &ctx.error;
|
||||
return &main_context.error;
|
||||
}
|
||||
*/
|
||||
void thread (char *str)
|
||||
{
|
||||
printf ("1.1: current stack frame: %p\n", CURRENT_STACK_FRAME);
|
||||
printf ("1.1: sleeping 2s in thread %d...\n", threadnum);
|
||||
sleep (2);
|
||||
printf ("1.1: current stack frame: %p\n", CURRENT_STACK_FRAME);
|
||||
printf ("1.1: returning to cothread 0\n");
|
||||
pth_mctx_restore (&main_context);
|
||||
}
|
||||
|
||||
void pthread (void* unused)
|
||||
{
|
||||
pth_mctx_t ctx;
|
||||
char *skaddr;
|
||||
|
||||
printf ("1: saving the main context\n");
|
||||
printf ("1: current stack frame: %p\n", CURRENT_STACK_FRAME);
|
||||
pth_mctx_save (&main_context);
|
||||
|
||||
while (1) {
|
||||
skaddr = malloc (1024 * 1024);
|
||||
|
||||
printf ("1: current stack frame: %p\n", CURRENT_STACK_FRAME);
|
||||
printf ("1: spawning a new cothread\n");
|
||||
pth_mctx_set (&ctx, thread, skaddr, skaddr + 1024 * 1024);
|
||||
printf ("1: new thread's stack frame will be in the heap at %p\n", skaddr);
|
||||
|
||||
printf ("1: current stack frame: %p\n", CURRENT_STACK_FRAME);
|
||||
printf ("1: switching to cothread %d...\n", ++threadnum);
|
||||
|
||||
printf ("1: current stack frame: %p\n", CURRENT_STACK_FRAME);
|
||||
pth_mctx_switch (&main_context, &ctx);
|
||||
|
||||
printf ("1: current stack frame: %p\n", CURRENT_STACK_FRAME);
|
||||
printf ("1: back now, looping\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
pthread_t tid;
|
||||
|
||||
printf ("0: current stack frame: %p\n", CURRENT_STACK_FRAME);
|
||||
printf ("0: creating the pthread\n");
|
||||
pthread_create (&tid, NULL, pthread, NULL);
|
||||
|
||||
// printf ("joining the pthread\n");
|
||||
// pthread_join (tid, NULL);
|
||||
|
||||
printf ("0: current stack frame: %p\n", CURRENT_STACK_FRAME);
|
||||
printf ("0: take five...\n");
|
||||
sleep(5);
|
||||
|
||||
printf ("0 current stack frame: %p\n", CURRENT_STACK_FRAME);
|
||||
printf ("exiting\n");
|
||||
|
||||
exit (0);
|
||||
}
|
||||
|
Loading…
Reference in a new issue