From 6972099f75765209c1cfefa315ae70a025912af4 Mon Sep 17 00:00:00 2001 From: halw Date: Tue, 25 May 2010 12:50:52 +0000 Subject: [PATCH] Updated for V6.6 Author:halw Date:2010-05-25T12:50:52.000000Z git-svn-id: https://svn.eiffel.com/eiffel-org/trunk@610 abb3cda0-5349-4a8f-a601-0c33ac3a8c38 --- .../once-features-multithreaded-mode.wiki | 63 +++++++++++++++---- 1 file changed, 51 insertions(+), 12 deletions(-) diff --git a/documentation/current/solutions/concurrent-computing/eiffelthread/eiffelthread-tutorial/once-features-multithreaded-mode.wiki b/documentation/current/solutions/concurrent-computing/eiffelthread/eiffelthread-tutorial/once-features-multithreaded-mode.wiki index 4ab8a757..1e470a42 100644 --- a/documentation/current/solutions/concurrent-computing/eiffelthread/eiffelthread-tutorial/once-features-multithreaded-mode.wiki +++ b/documentation/current/solutions/concurrent-computing/eiffelthread/eiffelthread-tutorial/once-features-multithreaded-mode.wiki @@ -13,36 +13,75 @@ Then the once feature is not initialized once per process but once per thread. Y By default, once features are once per thread. This means that when a once feature is called in a thread, the Eiffel run-time will check whether it has been already computed in this thread. If not, the once feature will be initialized and computed. This corresponds to the most commonly desired behavior for once features in multithreaded mode: most of the time, a once called in a thread is not likely to share its result with other threads. -This is only the default, however: you have a choice between "once per thread" and "once per process" +This is only the default, however: you may at times need to use "once per process" versus "once per thread". Objects created "once per process" in multithreading mode can be shared among threads. You can use a [[ET: Other Mechanisms#Adjusting once semantics with "once keys"|'''once key''']] to indicate the mode you wish to use. -==Specifying once per process or once per thread == +==Specifying once per thread or once per process == + +As mentioned above, in multithreaded mode, the default once syntax will ensure "once per thread", as in this example: -Here is what you will do to define a feature as a once per process: -class - TEST_ONCE_PER_PROCESS - -feature -- Access - object_per_thread: OBJECT -- Once per thread. once create Result.make end + +You could obtain the same effect by explicitly coding the "THREAD" once key: + + + object_per_thread: OBJECT + -- Once per thread. + once ("THREAD") + create Result.make + end + + +To ensure that a once function is executed only once per process, you would use the "PROCESS" once key: + + object_per_process: OBJECT -- New 'object' (once per process) -- that could be shared between threads -- without reinitializing it. + once ("PROCESS") + create Result.make + end + + + +The same concepts apply to once procedures. + + +{{note|Remember the effect of exceptions on the execution of once routines. If an exception occurs during the execution of a once routine, then '''that same exception will be raised again on each subsequent call''' to the once routine.}} + +===Obsolete syntax=== + +The syntax shown above is the current standard syntax. However in Eiffel code written for previous versions, you may run across once keys for multithreaded systems which are expressed in a different syntax. Specifically, the obsolete syntax used a feature's note clause to specify a once key, as in the following example. + + + object_per_process: OBJECT + -- Obsolete syntax + -- New 'object' (once per process) + -- that could be shared between threads + -- without reinitializing it. note once_status: global - once + once create Result.make end - -end -- class TEST_ONCE_PER_PROCESS -You can do the same with once procedures. + + +==Using once per object in a multithreaded system== + +It is possible to use a once key to specify a once function that is executed [[ET: Other mechanisms#Adjusting once semantics with "once keys"|once per object]]. However, in a multithreaded system, it is important to understand that no automatic synchronization of access occurs in this case. So the following caution is given. + + +{{caution|You should understand that in a multithreaded system, you must synchronize access to the result of a function executed once per object in the same way that you would synchronize access to class attributes. }} +{{SeeAlso|The Eiffel Tutorial section on [[ET: Other Mechanisms#Once routines and shared objects|once functions]] .}} + +