I encounter some issues using Agilent Vee Pro 9.32 and the documentation is not clear about multithreading, could someone help me please :
I want to have 2 threads, each generating random data and storing the generated data in a global variable. This global variable is a record with several fields, Thread 1 stores data in one field, Thread 2 stores data in another field (not the same as Thread 1). When I run the program, it starts running ok, but after a few seconds, it crashes. So I'm wondering:
- Is possible to use global variables in thread objects ?
- If I declare a global record with 2 fields, is it possible that 2 threads access different fields of the same record at the same time, or should I protect the access to the record ?
- Is there a way to protect the data such as a semaphore ? (cannot find any semaphore object)
Thank you.
Without trying it I would say that you _have_ to use global variables ( okay you could use a file or the like ) to communicate between threads and I would caution against a record as it is data container and as such changing one part in one thread and another in another thread seems fraught with danger.
If you want to compartmentalise the data you could create a 'structure' library - a VEE file which only declares ( and maybe initialises ) a set of data items. You can then access them by importing the library and accessing the various data values in the imported lib ( that also restricts scope to 'library' ).
Making your own semaphone using a boolean flag or 2 should be safe and straightforward enough. I thought ther might be more examples provided but there aren't... maybe we should make one. Why not post how you get on including your example and if appropriate I'll have have a hack at it as well.