#!/usr/local/bin/rune -x # limport "sys"; import "stdio"; subclass StreamPair as MyStuff { destructor method void destruct() { stdio.stderr->format("destructor called\n"); } } int main(int ac, char **av) { heap MyStuff strm; strm.pipehdx(); strm.reader(); strm.writer(); # Allow main to exit, it will wait for threads to # finish and strm sticks around (due to being a # heap allocation) until done. # } thread method void MyStuff.reader() { stdio.File @fp = &this.srd.file; char *buf; size_t len; result; stdio.stderr->format("reader begin\n"); while ((buf = fp->fgetbuf(&len)) != NULL) { stdio.stdout->fwrite(buf, len); stdio.stdout->fflush(); } fp->fclose(); stdio.stderr->format("reader finished error=%d\n", fp->fs.error); } thread method void MyStuff.writer() { stdio.File @fp = &this.swr.file; char *buf; size_t len; result; stdio.stderr->format("writer begin (line buffered)\n"); while ((buf = stdio.stdin->fgetbuf(&len)) != NULL) { fp->fwrite(buf, len); fp->fflush(); } stdio.stderr->format("writer finished\n"); fp->fclose(); }