|
From: Thomas R. T. <tr...@cs...> - 2003-04-17 13:59:35
|
valgrind seems to have a problem with swapcontext() tasking.
We use getcontext/setcontext/swapcontext
rather than setjmp/longjmp for tasking.
The *context routines are slower than *jmp
but seem to be a more official API for tasking.
For example the program below triggers messages such as:
==26015== Invalid write of size 4
==26015== at 0x42045D6C: __swapcontext (in /lib/i686/libc-2.2.93.so)
==26015== Address 0xBFFFE9BC is on thread 1's stack
This isn't a problem for us, since we can optionally use pthread tasking.
But I thought I should mention it.
Tom Truscott
#include <stdio.h>
#include <stdlib.h>
#include <ucontext.h>
ucontext_t child, parent;
#define STACKSZ (256*1024)
void childfunc(void)
{
printf("entering child\n");
swapcontext(&child, &parent);
printf("leaving child\n");
}
int
main()
{
printf("entering main\n");
getcontext(&child);
child.uc_link = 0;
child.uc_stack.ss_sp = malloc(STACKSZ);
child.uc_stack.ss_size = STACKSZ;
child.uc_stack.ss_flags = 0;
makecontext(&child, (void(*)())childfunc, 0);
swapcontext(&parent, &child);
printf("leaving main\n");
return 0;
}
|