SPONSORS:






User Tag List

Results 1 to 7 of 7
  1. #1
    Senior Member
    Join Date
    Aug 1999
    Location
    Cambridge, UK
    Posts
    470
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Multi-threading - automatically stop thread B when thread A has finished?

    I was wondering if anybody knew of a way to have one thread just drop everything it is doing when a different thread has finished it's task?
    My situation is that for obscure reasons not yet understood by our developers, our aut runs really slowly if it is the only client accessing the Oracle database back-end. In order to get round this problem and ensure it runs at a sensible speed, I have a script which retrieves data from the database through an ODBC connection, running in an infinite loop. This constant accessing of the database back-end keeps the aut running at a sensible speed. Unfortunately for automated testing, this means that I need silktest running on two computers just to perform automated testing on one of them.

    My intended solution is to have my scripts multi-threaded; one thread (thread A) will perform the normal testcase, while the other (thread B) will sit in an infinite loop retrieving data to keep the server ticking over. My problem is that I want to thread B to keep going until thread A has finished; is there any way anybody knows of having thread B automatically stop what it's doing (break out of it's infinite loop) when A finishes it's alloted task?

    Oh, and the other point is that I want to be able to spawn the two separate threads in TestCaseEnter, and then forget about them until TestCaseExit; I don't want to have to edit every single testcase to make this change.

    [This message has been edited by vincebowdren (edited 09-17-2001).]

  2. #2
    Senior Member
    Join Date
    Mar 2000
    Location
    pisctaway, NJ USA
    Posts
    188
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Multi-threading - automatically stop thread B when thread A has finished?

    No way to spawn a new thread onto the same PC using SILK.

    The ONLY way to do it is to call another plain old WINDOWS process and keep checking until it's done (or wait for it, but then your not out processing other things).

    Bad news, but I hope it helps.

    Tony

    ------------------

  3. #3
    Senior Member
    Join Date
    Aug 1999
    Location
    Cambridge, UK
    Posts
    470
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Multi-threading - automatically stop thread B when thread A has finished?

    Actually, a multi-threaded script need not have anything to do with two PCs. The standard use of multi-threading to interact with the aut on two machines simultaneously is just the standard use; of course having two threads both trying to use the gui on one machine at the same time would not be possible because they would interfere with each other, but if at least one of the scripts does not do anything through the gui, then that works fine. For example, it is quite easy to create a script with two threads which simultaneously perform SQL queries through the DBTester functions, without needing ever to access different machines.

    ------------------

  4. #4
    Senior Member
    Join Date
    Jun 2000
    Location
    Chicago, IL USA
    Posts
    383
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Multi-threading - automatically stop thread B when thread A has finished?

    There is no difficulty about multi-threading on a single machine. I do it all of the time. To isolate errors in my client/server tests, I have created an inheritable appstate that spawns a thread that continuously looks for errors in the log files on my servers and flags them.
    It has no significant effect on the main thread that manipulates the client GUI.
    The one detail that you need to know is that there is an implied "rendezvous" statement at the end of every testcase -- i.e. your testcase will not end until all of your threads have exited.
    To solve this problem you can use the "semaphore" statement for communication between the threads (it is documented in help, but not well).
    I don't have a lot time to explain it all today.
    Read the docs and post any questions.
    Good Luck.

    ------------------
    Rob Kapteyn

    [This message has been edited by RobKapteyn (edited 09-18-2001).]
    Rob Kapteyn, CSTE
    RobKapteyn@gmail.com

  5. #5
    Senior Member
    Join Date
    Aug 1999
    Location
    Cambridge, UK
    Posts
    470
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Multi-threading - automatically stop thread B when thread A has finished?

    Brilliant, thanks Rob.
    I managed to get it working with a shareable global variable rather than a semaphore, I don't know if there's any distinct benefit to the semaphore in this kind of situation?

    For anybody else looking for information about multi-threading, the key to this use of it is that spawned threads don't halt until they come across a rendezvous statement, which needn't be in the same section of code as the spawn statement. For my purposes, I spawned a separate thread in a function I call from TestCaseEnter, and put the rendezvous in TestCaseExit, though as Rob says, using the implicit rendezvous statement at the end of the testcase (to be specific, at the end of TestCaseExit) would work also.

    ------------------

  6. #6
    Senior Member
    Join Date
    Jun 2000
    Location
    Chicago, IL USA
    Posts
    383
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Multi-threading - automatically stop thread B when thread A has finished?

    Your explanation is good, but not completely correct. A spawned thread does not require a rendezvous to quit. It will quit when it gets to the end of the code in its spawned block. "rendezvous" pauses the main thread until ALL spawned threads have exited. This can create a situation, where one stuck thread halts the execution of everything else.

    A shared global variable is a perfectly acceptable way to coordinate two threads. Semaphores are confusing and complicated, but they are useful when you have more than two threads. Keep them in mind while you explore the power of multi-threading and you will know when it is time to use them.

    Good Luck.

    ------------------
    Rob Kapteyn
    Rob Kapteyn, CSTE
    RobKapteyn@gmail.com

  7. #7
    Senior Member
    Join Date
    Mar 2000
    Location
    pisctaway, NJ USA
    Posts
    188
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Multi-threading - automatically stop thread B when thread A has finished?

    This is VERY curious...

    A bunch of the posterx that say we can multi thread, please post an example for the following simple case. I ask of this because I HAVE NOT found a way to multi thread, as my post states, on one machine. I do not believe there is a way to multi thread like this.

    In this simple example, I have two things to acomplish. My client application is interacting with a GUI, lets say it's adding a customer to a database table. During ALL the time which the user is entering data, it is required to create a temporary file (on the PC) which contains the current and past data the operator is entering on the form (in case the client crashes so it can recover). So in this simple made up example, a good testcase would be to enter data on the form and as SOON as the file is created, stop entering on the form and verify the file agaist the data entered. My approach without threads would be to simply check if the file exists after I enter a value on each field or perhaps by a timer, but I wanna see some thread examples.
    For simplicity, lets say all I wanna know is if the file was created. In threading, the code that checks if the file exists would simply be in a while loop until the file is found then break. When the file is found, we should break out of the current FORM processing code and then do some file verification.

    This is not meant to disprove anyone, it is meant to gain some knowledge. I have tried countless times to create some simple threading cases and have not been able to.

    Tony

    ------------------

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.0.9 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Questions / Answers Form provided by vBAnswers (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominatevBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 02:35 AM.

Copyright BetaSoft Inc.