SPONSORS:






User Tag List

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

    Ways to synchronize multiple threads before continuing

    I have a testcase with multiple threads, each of which performs action A, then action B. I want to synchronize them after they have all performed action A, in order that they start performing action B simultaneously.

    The recommended way of doing this is by rendezvousing all the threads after they have performed action A, then spawning a new bunch of threads, each of which are to perform action B. My problem with this is that any local variable data acquired during execution of action A is lost (because it is local to each thread). So, I would like to be able to synchronize the threads, without rendezvousing and respawning them.

    One way I worked out of doing this is to use a semaphore and a shared boolean variable; when each thread has finished action A it acquires the semaphore, then checks to see if either the boolean variable has been set to true, or if the semaphore has reached zero (indicating that all the threads have reached the required point), and then continues (after setting the boolean variable to true, so kickstarting all the other threads). The problem with this method is that it is a bit messy, particularly with needing to define the semaphore and the boolean variable outside the testcase (in order that they are global variables, and the individual threads all see the same thing).

    Can anybody think of a tidier way of simply pausing all threads until they have reached the same point? For reference, here is the structure of my testcase, with the relevant point marked:

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

  2. #2
    Senior Member
    Join Date
    Dec 2001
    Location
    San Jose, CA
    Posts
    102
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Ways to synchronize multiple threads before continuing

    Vince,

    I would have created a list of list of string to compose of all available threads with values. Of course, it will be global variable.
    ie.
    list of list of string llsThreads = {"Thread1", "N/A"}
    {"Thread2", "N/A"}
    so on.

    Each thread which reaches the point of PerformA set the global variable with its value to true or something like "Done".
    Then, wait until the value reset to "Continue" by main program thread.
    So, basically each thread will be pooling until value becomes "Continue".

    Main program thread will be checking this global variable and reset to "Continue" if all threads have entered "Done".

    Hope that helps.

    Michael


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

  3. #3
    Senior Member
    Join Date
    Jul 1999
    Location
    Burlingame CA 94010
    Posts
    502
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Ways to synchronize multiple threads before continuing

    The share and access keywords will allow you to write to a global variable from different threads.

    declare the variable as:
    share LIST OF STRING lsData (or other type)

    then within the thread, use:
    access lsData
    ListAppend (lsData, sNew)

    You could use a record variable and store the machine name and its data.

    This is an obscure corner of SilkTest!!

    Hopet this helps.

    ------------------
    John W Green
    jwgreen@automationexpertise.com
    http://www.automationexpertise.com

  4. #4
    Senior Member
    Join Date
    Jul 1999
    Location
    Bellingham, WA USA
    Posts
    1,323
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Ways to synchronize multiple threads before continuing

    Rob,

    I'm intrigued by your solution. Can you expound a bit further on the locking of a file. How are you going about this?


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

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

    Re: Ways to synchronize multiple threads before continuing

    Vince -- I know your dilemma.

    Not only is Segue's documentation poor in this area, there are also a lot of SilkTest bugs in this area that will limit what you think you can do.
    Be sure to try everything out before you commit to a particular test architecture.
    Apparently some people at Segue think that multi-threaded, client-server testing is "obscure" (sorry John :-).
    But to our project -- online electronic trading -- it is natural and necessary.
    I wish Segue would try to get to know their customers better.

    I wanted to structure my testcases so that they could run in either of two modes:
    (1) a single SilkTest master controlling multiple SilkTest agents, and (2) multiple SilkTest masters running independently, but with some synchronization.

    This is virtually impossible to do with the buggy and complicated SilkTest variable sharing scheme.
    Our tests now share data by sharing test data FILES on a shared network drive.
    I have special read and write methods for each file, which quickly OPEN - READ - CLOSE, and AQUIRE LOCK - OPEN - WRITE - CLOSE - RELEASE LOCK.
    This simple system has worked much better that I ever expected.

    I have just recently begun using modified file locking methods to synchronize my testcase execution too.



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

  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: Ways to synchronize multiple threads before continuing

    I do not actually lock the files using the operating system, but just by the convention that I use in the test code.

    This convention is:
    1. Do not open a shared file without first AcquireLock() on it.
    2. AcquireLock() looks for the existence of a file with the same name, but a ".lck" extension. It sleeps as long as such a file exists. When there is no lock file (any longer)AcquireLock( , AquireLock() creates one.
    4. ReleaseLock() deletes the lock file.

    This system has proven to be quite robust, so far -- but I have not pushed it really hard yet :-)

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

 

 

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 07:12 AM.

Copyright BetaSoft Inc.