• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • Create a faction for Warcraft 3 and enter Hive's 19th Techtree Contest: Co-Op Commanders! Click here to enter!
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 21st Texturing Contest: Upgrade is now concluded, time to vote for your favourite set of icons! Click here to vote!

Why is recycling a global group safe?

Status
Not open for further replies.
Level 3
Joined
Aug 4, 2012
Messages
22
There is something about groups that I'm having a real hard time grasping.. maybe I'm thinking this issue too abstractly in terms of computer science.

So everyone knows that groups are notorious for leaking. The best practice to avoid this issue is to recycle them. A tutorial claims that you can declare one single group to use it across an entire map. (Unless your specific logic requires 2 groups for some nested logic or whatever, but this is besides the point).

My question is, how is this possible? Isn't this something susceptible to a race condition? What if two different spells that use the same group are invoked at the same time? Does Warcraft 3 put some sort of lock on accessing this variable so that any code accessing the group is guaranteed to be ran sequentially? To me, this practice seems super dangerous but I've seen plenty of maps declare a single global group, so it must work but I really don't get why this doesn't break stuff.
 
Level 19
Joined
Mar 18, 2012
Messages
1,716
Please only post in Triggers&Scripts if you have actual code you want to discuss.

Move to World Editor Helping Zone.

-----

First of all group handles do not leak per se. There is no evidence for this assumption.
Agreed the GUI has a couple of flaws when it comes to group related functions,
but not because of to the group handle itself.

In most cases one constant group can be shared over your entire code.
People tend to use bj_lastCreatedGroup.
Exceptions:
  • You need more than one group. ( tracking damaged units, group swapping, ... )
  • Recursion, trigger events, .... + the same group.

There is GroupUtils to get and recycle groups dynamically.
 
Last edited:
My question is, how is this possible? Isn't this something susceptible to a race condition?

Luckly, wc3 is completely single-threaded, so you do not have to do multicore debugging.
But this is still a stupid idea, better use a system that recycles a number of groups so that every time you require a group you always get a free one, no matter what, it's much safer and it's sound logic.

Using one group is just stupid no matter what, it'll get you in trouble for no gain.
 
Level 7
Joined
Oct 19, 2015
Messages
286
All JASS code is run sequentially, so race conditions can not occur.

That being said, using a single group is not necessarily safe. If a trigger preforms an action that runs the event of another trigger, the second trigger will interrupt the first and the first will only continue once the second one finishes. If both use the same group and the first one is using it when it triggers the second one, a bug will occur.
 
Level 3
Joined
Aug 4, 2012
Messages
22
Luckly, wc3 is completely single-threaded, so you do not have to do multicore debugging.
But this is still a stupid idea, better use a system that recycles a number of groups so that every time you require a group you always get a free one, no matter what, it's much safer and it's sound logic.

Using one group is just stupid no matter what, it'll get you in trouble for no gain.

What library is recommended for recycling groups? GroupUtils seem really outdated now
 
Status
Not open for further replies.
Top