• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Solved] Parallelity in WC3

Status
Not open for further replies.
Level 7
Joined
Jan 30, 2011
Messages
267
Is there any task parallelity in warcraft?
to be more precise, this is my problem:
i have quite a lot of loop code that has to be executed on game begin (= when loadscreen is gone)
now theres the problem that wc3 terminates threads that are working too long
so i tried this:

JASS:
struct Test
private static method init takes nothing returns nothing
    local integer i = 0
    call DestroyTimer(GetExpiredTimer())
    loop
        exitwhen i == 100
        call work()
        set i = i+1
    endloop
endmethod

private static method onInit takes nothing returns nothing
    call TimerStart(CreateTimer(), 0, false, function thistype.init)
endmethod
endstruct

i turned it to this:
JASS:
struct Test
private static integer i = 0
private static method loopcode takes nothing returns nothing
    call work()
    set i = i+1
endmethod

private static method init takes nothing returns nothing
    local trigger trig = CreateTrigger()
    local integer k = 0
    loop
        exitwhen k == 100
        call TriggerAddAction(trig, function thistype.loopcode)
        set k = k+1
    endloop
    call TriggerExecute(trig)
endmethod

private static method onInit takes nothing returns nothing
    call TimerStart(CreateTimer(), 0, false, function thistype.init)
endmethod
endstruct

the first code is being terminated at some point, the second one runs through
this makes me think that for each action added to a trigger a new thread is created
if thats so, can there be parallelity problems?
on my computer the 100 executions of method loopcode are all 1 after the other, but i only have a weak dual core without hyperthreading
 
Last edited by a moderator:
Level 7
Joined
Jan 30, 2011
Messages
267
thx for your answer
after having the created this post i continued googling this matter
i found a post where someone said that these "threads" are no actual threads
he said that the whole code is being executed in only 1 actual thread (as radicool said)
i would like to hear the oppinion of more people who can either confirm or deny this statement, because it's very important for me =)
 
well, AFAIK trigger execute runs the trigger in a new "thread" (as you already said in the post, it's not an actual thread, it's just some kind of a way used by wc3 to "separate" operations so as we can avoid hitting the OP limit)...

that is why, even if your first code stops running coz it hits the OP limit, the second one doesn't [since the k loop is "separate" from the i loop which runs work]...

though 100 iterations shouldn't be a problem unless that work function does a lot of things
 
^yeah.

Wc3 isn't multi-threaded. It emulates its threading, through scheduling "threads" and pausing them when needed. When you hit ~300,000 bytecode operations, the "thread" will end (this is known as the op-limit). However, you can "start a new thread" through particular functions (ForForce, TimerStart, ExecuteFunc, TriggerExecute, TriggerEvaluate, etc.), which will reset the op-limit (operations -> 0), most likely in addition to other things (e.g. event responses may change value).

The key thing to note is that threads in wc3 are not exactly the same as the threads we are familiar with. They are similar, but it is not multi-threaded. Things are queued/scheduled, and paused in the case of TriggerSleepAction(seconds)/sync functions. When a thread is "paused", it doesn't pause the whole game's global thread. That emulated-thread just waits for the necessary time and becomes scheduled again. Two "threads" can't run at the same time.
 
Status
Not open for further replies.
Top