Printer FriendlyEmail Article Link

iTest: In iTest how to share variables in threading

Environment/Versions

Spirent iTest

Answer

 We need to create global variables to share a value between different threads.

 The behavior of global variables in multi-threading is as follows:

  #Simultaneous execution

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

Thread1

              Eval gset aaa 1

              Readfile [huge data]   -> Store response as aaa global variable, it takes 2 minutes to finish this step

Thread2

              sleep 5

              Eval puts [gget aaa]

In above condition both threads are running in parallel, so in second thread the value returns in variable(aaa) is “1” , thread1 will not lock the global variable(aaa).

#Simultaneous execution

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

Thread1

              Step1 - Eval gset aaa 1

              Step2 - Readfile [huge data]   -> Store response as aaa global variable, it takes 2 minutes to finish this step

Thread2

              Step1 - sleep 5

              Step2 - Eval puts [gget aaa]  ->[Here we will get value 1]

              Step3 - waitthread

              Step4 - Eval puts [gget aaa]  ->[This steps retrieves data from step2 of thread1]

In above condition both threads are running in parallel, so step2 returns value “1”, step3 waits for thread1 to complete this task and enters into step4. So, step4 retrieves data from step2 of thread1.

 


Product : Velocity Portfolio,Velocity iTest