Difference between revisions of "Talk:Transactions"

(Examples please)
(A couple examples.)
Line 4: Line 4:
  
 
I think we need to see some examples (well, I do for one).
 
I think we need to see some examples (well, I do for one).
 +
 +
The main thing to remember is that the proposal states that all features calls are asynchronous.
 +
 +
Transactions are assured with transactional memory, probably implemented as software transactional memory.
 +
 +
Example of transaction:
 +
feature
 +
correct_removal(container: DISPENSER) is
 +
 transaction  --  This is a transaction so it is assured to be atomic and isolated
 +
  if
 +
   not(container.is_empty)
 +
  then
 +
   container.remove
 +
  end
 +
 end
 +
 +
This feature is assured to be correct because is is isolated and atomic with respect to the system.  If the container has been modified between the call to is_empty and remove, the feature would be aborted and retried.
 +
 +
feature
 +
incorrect_removal(container: DISPENSER) is
 +
 do
 +
  if
 +
   not(container.is_empty)
 +
  then
 +
   container.remove
 +
  end
 +
 end
 +
 +
This is the standard example of concurrency issues with preconditions.  The container can change between the call to is_empty and remove.  Using transactions avoids this.
 +
 +
Example of concurrency:
 +
feature
 +
write_all_files is
 +
 do
 +
  write_file_1
 +
  write_file_2
 +
  write_file_3
 +
  write_file_4
 +
 end
 +
 +
Since all feature calls would be asynchronous, the four write_file features could be executed in parallel if the runtime decides to do so.  This is not a transaction so isolation across these calls is not assured.

Revision as of 10:33, 6 April 2007

Discussion of the feasibility and desirability of implementing transactional concurrency in Eiffel.

Examples please

I think we need to see some examples (well, I do for one).

The main thing to remember is that the proposal states that all features calls are asynchronous.

Transactions are assured with transactional memory, probably implemented as software transactional memory.

Example of transaction: feature correct_removal(container: DISPENSER) is  transaction -- This is a transaction so it is assured to be atomic and isolated   if    not(container.is_empty)   then    container.remove   end  end

This feature is assured to be correct because is is isolated and atomic with respect to the system. If the container has been modified between the call to is_empty and remove, the feature would be aborted and retried.

feature incorrect_removal(container: DISPENSER) is  do   if    not(container.is_empty)   then    container.remove   end  end

This is the standard example of concurrency issues with preconditions. The container can change between the call to is_empty and remove. Using transactions avoids this.

Example of concurrency: feature write_all_files is  do   write_file_1   write_file_2   write_file_3   write_file_4  end

Since all feature calls would be asynchronous, the four write_file features could be executed in parallel if the runtime decides to do so. This is not a transaction so isolation across these calls is not assured.