greeting, folks. first off, is there an archive for this list? I couldn't find one when i googled.
secondly, I'm workng on coroutines in GStreamer, a streaming media framework. right now we have our own implementation of coroutines. we also have support for pthreads, to offer an alternative scheduling method. we will have both coroutines and preemptive threads into the forseeable future. this means that on Linux, the primary development platform, we will be using pthreads in the LinuxThreads incarnation. that said, it seems that LinuxThreads' errno hack is messing with pth. The sample code attached fails, segfaulting in __errno_location: (gdb) bt #0 0x4002b6e1 in __errno_location () from /lib/libpthread.so.0 #1 0x400856d2 in vfprintf () from /lib/libc.so.6 #2 0x4008e4d6 in printf () from /lib/libc.so.6 #3 0x08048719 in thread (str=0x804882e "[\201\022\022") at test-pth.c:12 #4 0x40083834 in makecontext () from /lib/libc.so.6 #5 0x080487d1 in pthread (unused=0x4015a008) at test-pth.c:32 is there a way to get around this? our coroutines implementation is woefully insufficient, and I would love to use pth due to its portability and extensibility. many thanks in advance for your insights. best regards, wingo. ps. i use a hacked version of pth, including only what is necessary to use pth_mctx.c, because we will do the scheduling ourselves. the test app just tests the functions of pth_mctx.c.
#include "pth_p.h" #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <pthread.h> pth_mctx_t main_context; int threadnum = 0; void thread (char *str) { printf ("sleeping 2s in thread %d...\n", threadnum); sleep (2); printf ("returning to thread 0\n"); pth_mctx_restore (&main_context); } void pthread (void* unused) { pth_mctx_t ctx; char *skaddr; pth_mctx_save (&main_context); while (1) { skaddr = malloc (1024 * 1024); pth_mctx_set (&ctx, thread, skaddr, skaddr + 1024 * 1024); printf ("switching to thread %d...", ++threadnum); pth_mctx_switch (&main_context, &ctx); printf ("back now, looping\n"); } } int main (int argc, char *argv[]) { pthread_t tid; pthread_create (&tid, NULL, pthread, NULL); pthread_join (tid, NULL); exit (0); }