From 471a50ef1391f6399664f8b992da7a67c32c8b86 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Tue, 26 Apr 2016 16:49:47 +0200 Subject: Fix hibernation subtlety --- lib/stdlib/doc/src/gen_statem.xml | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'lib/stdlib/doc') diff --git a/lib/stdlib/doc/src/gen_statem.xml b/lib/stdlib/doc/src/gen_statem.xml index 91332fbdde..ec7f267c64 100644 --- a/lib/stdlib/doc/src/gen_statem.xml +++ b/lib/stdlib/doc/src/gen_statem.xml @@ -216,19 +216,23 @@ erlang:'!' -----> Module:StateName/3 if bad arguments are given.

- The gen_statem process can go into hibernation (see - - erlang:hibernate/3 - ) if a + The gen_statem process can go into hibernation; see + + proc_lib:hibernate/3. + + It is done when a state function or Module:init/1 specifies hibernate in the returned Actions - list. This might be useful if the server is expected to be idle - for a long time. However use this feature with care - since hibernation implies at least two garbage collections - (when hibernating and shortly after waking up) and that is not - something you would want to do between each event on a busy server. + list. This feature might be useful to reclaim process heap memory + while the server is expected to be idle for a long time. + However, use this feature with care + since hibernation can be too costly + to use after every event; see + + erlang:hibernate/3. +

@@ -619,7 +623,8 @@ handle_event(_, _, State, Data) -> to wait for the next message. In hibernation the next non-system event awakens the gen_statem, or rather the next incoming message awakens the gen_statem - but if it is a system event it goes back into hibernation. + but if it is a system event + it goes right back into hibernation. @@ -645,9 +650,13 @@ handle_event(_, _, State, Data) -> before going into receive to wait for a new external event. - If there are enqueued events the hibernate - is ignored as if an event just arrived and awakened - the gen_statem. + If there are enqueued events, + to prevent receiving any new event; a + + garbage_collect/0 + is done instead to simulate + that the gen_statem entered hibernation + and immediately got awakened by the oldest enqueued event.

-- cgit v1.2.3