I have just implemented world stop garbage collection.
I'm not sure if it works yet. Here's an outline.
But first:
WARNING WARNING WARNING.
************************
The user service calls that do garbage collection are
NO LONGER SERVICED BY flx_sync. They're handled instead
in the doflx subroutine, along with other nasty service
calls such as spawning a pthread.
The reason (obviously) is that these routines are now
guarded by a world stop. All pthreads running
Felix synchronous systems using a common collector must now
stop to permit collection to occur, for example:
case svc_collect:
{
thread_control->world_stop();
gcp->collector->collect();
thread_control->world_start();
}
This is to ensure NO threads have any Felix heap pointers
on their machine stacks during collection, and also that
the heap remains stable during collection.
Async threads are NOT affected. For example socket I/O requests
handled asynchronously still get serviced (it needs to be
checked that this process doesn't fiddle with any gc roots).
The main doflx() subroutine calls:
thread_control->yield();
whenever the synchronous system blocks, or issues an
async (general) service call. This may be fiddled with
to get the collection to occur more frequently, but at
present the ONLY way to actually trigger a collection
is with an explicit service call.
The current implementation is below. I have no idea
if it works (however all existing code continues to run,
probably because none of it actually ever does a collection :)
The code fiddles the thread_counter so its meaning is actually
'running threads'.
------------------
struct thread_control_t
{
flx_ts_counter_t thread_counter;
bool do_world_stop;
flx_condv_t stop_guard;
flx_mutex_t stop_mutex;
thread_control_t () : do_world_stop(false) {}
void add_thread() { ++thread_counter; }
void remove_thread() { --thread_counter; }
// stop the world!
void world_stop() {
flx_mutex_locker_t m(stop_mutex);
do_world_stop = true;
--thread_counter;
while(*thread_counter>0) stop_guard.wait(&stop_mutex);
}
// restart the world
void world_start() {
flx_mutex_locker_t m(stop_mutex);
++thread_counter;
do_world_stop = false;
stop_guard.broadcast();
}
void yield() {
flx_mutex_locker_t m(stop_mutex);
if (do_world_stop)
{
--thread_counter;
while(do_world_stop) stop_guard.wait(&stop_mutex);
++thread_counter;
}
}
};
--
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language