On 8/19/07, skaller <[EMAIL PROTECTED]> wrote: > On Sun, 2007-08-19 at 13:13 +0300, Rhythmic Fistman wrote: > > > My driver itself cheats in this respect, using > > an schannel with some c code that reschedules every fthread > > hanging on an schannel, as though you executed a "read n times, > > discarding result". Um. > > I actually think you should use the standard driver.
Well, that wouldn't be so hard - apart from hiding the flx rtl headers behind an apaque void*, it only really adds one thing*: the ability to dump all the readers of an schannel back into the active list, that is it "fakes" N writes. I tried rewriting that in felix using real writes, but I get gc "removed non root" errors and the whole thing's a bit hairy, as the code written uses svc calls and can't be guaranteed to finish by simply executing its continuations. I need to be able to do this step in one fell swoop. The motivation for all this is that my driver + support flx file provides a global synchrosing timer where n fthreads can run, then at a certain point, asked to be suspended for n time units. I implement this on the fthread side via reads on an schannel, descheduling the fthreads and on the driver side dumping all those fthreads back onto the active list with the fake writes. Tacked onto the end of this mail for yer consideration is my attempt to translate the meatiest part of the driver into felix, i.e. into a plain old library function. * Actually two, no, three things - it garbage collects and upon destruction calls gc::free_all_mem, the final collection. Ah, and it also adds a fn for scheduling exported flx symbols from C, optionally returning the fthread*, which it can deschedule. spawn_fthread can't do that yet, but that's not necessarily a bad thing. descheduling via an fthread ptr's not terribly robust - I only do it on non terminating fthreads. > If you can't do what you want, I need to know the problem and > fix it so you can. > The main constraint at the moment is that the standard driver > does *require* pre-emptive thread support. That's not so terrible. I'm using pretty much all of the other libraries it requires anyway. RF int sync_drv_data::unblock_all() { #if 1 // fprintf(stderr, "activating in correct order?\n"); fthread_t* reader; int n = 0; // simulates an fthread writing enough times to wake all on ticker. // tricky. whilst blocked on the driver's ticker the threads are not // referenced. For this the ticker itself is rooted. while((reader = ticker->pop_reader())) // all must read from ticker { readreq_t * pr = (readreq_t*)reader->get_svc()->data; // NOOOOOO - this has to be a gc pointer! that was hard to find. // another level of indirection. better to get some flx code to do // it. same goes for ticker allocation and setting. //*(void**)pr->variable.get_data() = *(void**)pr->variable = //&ticker_value; // anyway, stale because pointer was taken new(fv.collector, _int_ptr_map)int(ticker_value); // I'm pretty sure these guys activate in the order they slept active.push_front(reader); fv.collector.add_root(reader); n++; } ticker_value++; // someone might use this value one day return n; #else int n; // con_t* c = flx_unblock_all(ptf, ticker_value, &n); // while( c ) c = c->resume(); // simple continuation running wasn't handing svc calls like write spawn(flx_unblock_all(ptf, ticker_value, &n), 0); ss.frun(); // runs one sync ticker_value++; // someone might use this value one day return n; #endif } gen has_reader[t]: schannel[t] -> bool = "$1->waiting_to_read->head != NULL"; // this isn't quite working, can't be run by simple continuation execution, // needs own svc savvy driver, which is a bit too second order for me. also // getting gc error: "removed non root". private proc flx_unblock_all(tick: int, npopped: &int) { var n = 0; while{ has_reader(ticker) } { // peek readers so we don't desched n++; write(ticker, tick); // pop a reader }; *npopped = n; } ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language