Threads and shared memory

More
20 years 9 months ago #17968 by GrandpaTrout
I wrote a small program to test some theories about how memory is shared between threads. The SDK states that threads have seperate memory, and cannot share.

But it does not comment on how globals are handled. Or how groups are handled. Tasks often want to move around groups of ships, or lists of objects.

I found some surprising results:
Both lists and groups can be shared between tasks.

I created a list and group in a first task, added some items, and then placed both into globals. (The group in a global handle).

I then used a second task to look at list and group and see if the items were there. They were. I then added another item.

I then used the first task to check if the new items showed up. They did.

I did not expect that groups could be used to share, because you must "create" a group (thus allocating memory). But it seems to work. This contradicts earlier findings - so I am betting it breaks in weird and unexpected ways.

Full source and package file here:

www.i-war2.com/epic/files/MemTest.zip

-Gtrout

Please Log in or Create an account to join the conversation.

More
20 years 9 months ago #9036 by MajorTom
Replied by MajorTom on topic Threads and shared memory

Originally posted by GrandpaTrout

I
This contradicts earlier findings - so I am betting it breaks in weird and unexpected ways.


-Gtrout


The winner (culprit) is: Group.Flatten() !!!

We use group globle handles to deal with bot groups in the MP games but always copy them into a list (like you did) before changing properties because Group.Flatten() side effects the original groups.


Have Gun, Will Travel

Please Log in or Create an account to join the conversation.