I want to use pth to get coroutine functionality in C++. The
following program illustrates the concept:
#include "pth.h"
#include <iostream>
pth_t main_thread;
static void *f(void *a)
{
std::cout << "f1" << std::endl;
pth_yield(main_thread);
std::cout << "f2" << std::endl;
return 0;
}
int main()
{
int e = pth_init();
main_thread = pth_self();
pth_t t = pth_spawn(PTH_ATTR_DEFAULT, f, NULL);
pth_yield(t);
pth_yield(t);
}
(This doesn't really illustrate _why_ I need coroutines, but it
does illustrate essentially how I will be using them.)
This program compiles and runs with the expected behavior.
However, valgrind (http://valgrind.kde.org/) complains about
numerous memory access errors. I am not certain if these are
real or false positives.
Here's an example. After calling the first pth_yield(t), it
complains about invalid memory reads:
==2775== Invalid read of size 4
==2775== at 0x3C153BA1: swapcontext (in /lib/tls/libc-2.3.2.so)
==2775== Address 0x3C25E314 is 256 bytes inside a block of size
760 alloc'd
==2775== at 0x3C01E338: malloc (vg_replace_malloc.c:105)
==2775== by 0x3C0267B9: __pth_tcb_alloc (in
/g/g10/rwa/redhat-packages/pth-1.4.1/lib/libpth.so.14.0.21)
==2775== by 0x3C02993A: pth_spawn (in
/g/g10/rwa/redhat-packages/pth-1.4.1/lib/libpth.so.14.0.21)
==2775== by 0x8049985: main (minimal.C:20)
Is there an error in my program? Or does this look like some
kind of false positive?
Thanks,
Bob
______________________________________________________________________
GNU Portable Threads (Pth) http://www.gnu.org/software/pth/
Development Site http://www.ossp.org/pkg/lib/pth/
Distribution Files ftp://ftp.gnu.org/gnu/pth/
Distribution Snapshots ftp://ftp.ossp.org/pkg/lib/pth/
User Support Mailing List [EMAIL PROTECTED]
Automated List Manager (Majordomo) [EMAIL PROTECTED]