Intelligent Automation & Macro Software  

Go Back   Automation Anywhere, Inc. Forums > Products Zone > Automation Anywhere
Register FAQ Search Today's Posts Mark Forums Read

Automation Anywhere Post messages and questions related to Automation Software here.


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-28-2009, 10:09 PM
rahul rahul is offline
Junior Member
 
Join Date: Dec 2008
Posts: 11
Default How to avoid race condition while executing multiple tasks?

10 tasks are running in parallel. Some instructions (at random time intervals using delays) may try to read a File “FileA” in each task. At one time only one task should read the file, other files trying to read the same file should wait until the file is free to read (no task is reading the file).
Is there any way to achieve this though Automation Anywhere?
Reply With Quote
  #2 (permalink)  
Old 01-30-2009, 11:45 AM
forumsupport forumsupport is offline
Senior Member
 
Join Date: Apr 2007
Posts: 1,342
Default

Hello,

You cannot run two Automation Anywhere tasks simultaneously. However, you can run two exes of task simultaneously.

Can you please tell us, all the tasks are accessing the text file through 'Read from Text file' variable?

When more than one exe tries to access same text file, the operating system will grant full access to the first exe and the subsequent exes will get the read only access. However, the exe will continue to run. Read only access would not stop running the exe.

Hope that helps.
Reply With Quote
  #3 (permalink)  
Old 02-02-2009, 12:51 PM
rahul rahul is offline
Junior Member
 
Join Date: Dec 2008
Posts: 11
Default

Yes I wanted to refer to exe files only. So,does that mean we cannot achive this though Automation Anywhere, coz my requirement is to allow only one exe to read the common text file one at a time ?

Is there any other workaround in Automation Anywhere?
Reply With Quote
  #4 (permalink)  
Old 02-03-2009, 03:17 AM
forumsupport forumsupport is offline
Senior Member
 
Join Date: Apr 2007
Posts: 1,342
Default

Hello,

Can you please tell us, is your task just reading the text file or it is also writing in it?

In later case i.e. task is writing in a text file, an error will be produced when two exes tries to access the same file at the same time. You can handle this error using Error Handling command (Available only in Enterprise version). You can continue the task after the block where the error occurs, or stop the task. You can find this command under 'Advanced' command category.

When an error occurs, Automation Anywhere can take the following actions:
. Take a snapshot of the screen
. Run another task
. Log data in a file
. Send an email

All four options can be performed together or in combination. For example, you can run a task and log data into a file.

Hope that helps.

Last edited by forumsupport; 02-04-2009 at 08:07 AM.
Reply With Quote
  #5 (permalink)  
Old 02-03-2009, 11:24 AM
rahul rahul is offline
Junior Member
 
Join Date: Dec 2008
Posts: 11
Default

Hi,

Actually multiple tasks will read this file only one task will write the status in the file. While TaskA is updating the file no other task should read the shared file. But I am not able to stop any task from reading this file, I tried with random delays in different tasks couldn't stop other tasks from reading the file but it didn't work.

So,How do I stop other tasks from reading this file?
Reply With Quote
  #6 (permalink)  
Old 02-04-2009, 09:50 AM
forumsupport forumsupport is offline
Senior Member
 
Join Date: Apr 2007
Posts: 1,342
Default

Hello,

What you can try is,

. In TaskA insert 'Create File' command to create a temporary file say ToBeDeleted.txt on shared network, before the command that is writing the status in the shared file.
. At the end of task, insert 'Delete Files' command to delete ToBeDeleted.txt file.

Text format of commands in TaskA would appear something like this,

Create Text File "X:\ToBeDeleted.txt"
Log to File: Logging the status in "X:\SharedFile.txt"
Delete Files "X:\ToBeDeleted.txt"

. In TaskB, insert Loop command with condition in order to wait until X:\ToBeDeleted.txt exists. As soon as TaskA deletes the file, the Loop condition would become false and task would come out of loop to execute subsequent commands in TaskB.

Loop While File Exists("X:\ToBeDeleted.txt")
Delay: (300 ms)
End Loop
Comment: Commands in TaskB should follow

Hope that helps.
Reply With Quote
  #7 (permalink)  
Old 02-05-2009, 07:31 AM
rahul rahul is offline
Junior Member
 
Join Date: Dec 2008
Posts: 11
Default

Hi,

Loop While File Exists("X:\ToBeDeleted.txt")
Delay: (300 ms)
End Loop

I see the problem with this code piece is that in case of multiple exe running and say 5 exe files waiting for the condition to be true and when its true at least 3 exe will get in side the loop and therefore we fail to avoid the race condition again.

Please let me know if you otherwise.
Reply With Quote
  #8 (permalink)  
Old 02-07-2009, 01:29 AM
forumsupport forumsupport is offline
Senior Member
 
Join Date: Apr 2007
Posts: 1,342
Default

Hello,

The solution was for the condition, while TaskA is updating the file no other task should read the shared file.

If you wish the same thing for all the tasks i.e. at a time only one task can read or write a file then include following commands in the beginning of every task,

Loop While File Exists("X:\ToBeDeleted.txt")
Random Delay ( From 1000 to 3000 ms)
End Loop
Create Text File "X:\ToBeDeleted.txt"
Comment: Commands in Task should follow
Delete Files "X:\ToBeDeleted.txt"

Insert Random delay inside the loop so that no two tasks can get inside at the same time.

Hope that helps.
Reply With Quote
  #9 (permalink)  
Old 02-09-2009, 11:15 AM
rahul rahul is offline
Junior Member
 
Join Date: Dec 2008
Posts: 11
Default

Hi,

Through random delay we are lowering the probability of any race condition but not eliminating it 100 %, right ?
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -7. The time now is 10:04 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.0.0 ©2007, Crawlability, Inc.
Copyright © 2003-2011 Automation Anywhere, Inc. All rights reserved