mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-16 13:26:36 +00:00
259c8c394c
Original commit message from CVS: some compile fixes, api changes, and i added the ability to create new chunks on the stack, which can extend the main thread's stack up to 8M under linuxthreads. thanks to billh for the {set,get}rlimit tip. on the other hand, there's a nasty bug in cothreads when they are run without gthreads that i'm still tracking down. that's the last bug though, at this point. the commit is to syn the repository with my working copy before moving cothreads to a separate module.
70 lines
1.8 KiB
C
70 lines
1.8 KiB
C
#include "pth_p.h"
|
|
#include <unistd.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include "linuxthreads.h"
|
|
|
|
pth_mctx_t main_context;
|
|
int threadnum = 0;
|
|
|
|
void cothread (void)
|
|
{
|
|
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 = alloca (64 * 1024);
|
|
|
|
printf ("1: current stack frame: %p\n", CURRENT_STACK_FRAME);
|
|
printf ("1: spawning a new cothread\n");
|
|
pth_mctx_set (&ctx, cothread, skaddr, skaddr + 64 * 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 ("0: %d\n", pthread_self());
|
|
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);
|
|
}
|
|
|