changeset 18491:477b5916cafe stable

doc: Update function locking section with correct usage of mlock (bug #41627) * func.txi (Function Locking): Update description of function locking to show correct usage of the mlock function.
author Mike Miller <mtmiller@ieee.org>
date Thu, 20 Feb 2014 00:44:14 -0500
parents 4c2465444a96
children e4c319ed2414
files doc/interpreter/func.txi
diffstat 1 files changed, 11 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/doc/interpreter/func.txi	Tue Feb 18 09:59:52 2014 -0500
+++ b/doc/interpreter/func.txi	Thu Feb 20 00:44:14 2014 -0500
@@ -1052,18 +1052,22 @@
 As an example,
 
 @example
-mlock ("my_function");
+@group
+function my_function ()
+  mlock ();
+  @dots{}
+@end group
 @end example
 
 @noindent
-prevents @code{my_function} from being removed from memory, even if
-@code{clear} is called.  It is possible to determine if a function is
-locked into memory with the @code{mislocked}, and to unlock a function
-with @code{munlock}, which the following illustrates.
+prevents @code{my_function} from being removed from memory after it is
+called, even if @code{clear} is called.  It is possible to determine if
+a function is locked into memory with the @code{mislocked}, and to unlock
+a function with @code{munlock}, which the following illustrates.
 
 @example
 @group
-mlock ("my_function");
+my_function ();
 mislocked ("my_function")
 @result{} ans = 1
 munlock ("my_function");
@@ -1078,11 +1082,11 @@
 @example
 @group
 function count_calls ()
+  mlock ();
   persistent calls = 0;
   printf ("'count_calls' has been called %d times\n",
           ++calls);
 endfunction
-mlock ("count_calls");
 
 count_calls ();
 @print{} 'count_calls' has been called 1 times
@@ -1093,22 +1097,6 @@
 @end group
 @end example
 
-@noindent
-It is, however, often inconvenient to lock a function from the prompt,
-so it is also possible to lock a function from within its body.  This
-is simply done by calling @code{mlock} from within the function.
-
-@example
-@group
-function count_calls ()
-  mlock ();
-  persistent calls = 0;
-  printf ("'count_calls' has been called %d times\n",
-          ++calls);
-endfunction
-@end group
-@end example
-
 @code{mlock} might equally be used to prevent changes to a function from having
 effect in Octave, though a similar effect can be had with the
 @code{ignore_function_time_stamp} function.