Jump to content
UBot Underground

local lists & multi-threading


Recommended Posts

I'm struggling a bit with list scopes tonight, pertaining to multi-threading. I see that "add item to list" and "add list to list" have a scope option, so I can set them as local lists in a thread. What I don't understand is why list commands such as "clear list" do not have a scope option? How do I clear a local list?

 

I'm trying to thread one of my bots that is currently unthreaded. The threaded part will need to write data to temporary lists, manipulate that list data using other lists, and then output certain results to a global table. What I'm struggling with is the full grasp of controlling a list named #data that will be existing with 10 unique local versions of it in 10 threads.

Link to post
Share on other sites

Good question. :)

 

I think you should first know that local list is local to define command/function, and not to thread.

 

Clear command actually clears both lists, local and global. You can test that with the code bellow:

clear list(%LIST)
add item to list(%LIST, 1, "Delete", "Global")
add item to list(%LIST, 2, "Delete", "Global")
thread {
    set(#LIST Local, $Function(), "Global")
}
define $Function {
    clear list(%LIST)
    add item to list(%LIST, 2, "Delete", "Local")
    if($true) {
        then {
        }
        else {
            clear list(%LIST)
        }
    }
    return(%LIST)
}

CONCLUSION:

Global list "%LIST" (which can be seen in debugger) is actually cleared  when "$Function" is ran, and that local list really holds value 2, since it gets returned to variable "#LIST Local".

Link to post
Share on other sites

Hello UBotDev, thanks for the information.

 

I keep reading that local scope is only local to the define, and not a thread, but I'm a bit unsure how local scope helps in multi-threading then. If I have a define that contains a local variable and a local list, and that define is going to be called by 10 threads, how does the local scope help me if the 10 threads are going to be each overwriting the local variable and local list from the define simultaneously?

 

Thanks again for any and all help.

Link to post
Share on other sites

They wont be overwriting local variables/list if you call define from 10 threads.

 

Local variable/list is local to define command/function when you run it, so if you run a 2nd instance of that define command/function, that one will also keep variables/list local to that run and won't interfere with first thread.

  • Like 3
Link to post
Share on other sites

Aha! Now that makes perfect sense! Thank you for taking the time to explain. Now I grasp it.

 

Thanks also for the free plugins you provide. I'm getting ready to try and utilize your advanced shell commands to hide some excel macros running from a bat file.

 

:)

Link to post
Share on other sites

Nice to hear. No problem at all!

 

OFF-TOPIC:Good luck with Advanced Shell...you can hide the window+use batch command/function instead of external file (if you'll need help email me or open a thread here).

Link to post
Share on other sites
  • 1 month later...

This Thread was very helpful. still haven't totally grasped it yet but im almost there.. Wiremarket, thanks for asking. Ubotdev.com Thank you for answering it so detailed..

Link to post
Share on other sites
  • 11 months later...

Good question. :)

 

I think you should first know that local list is local to define command/function, and not to thread.

 

Clear command actually clears both lists, local and global. You can test that with the code bellow:

clear list(%LIST)
add item to list(%LIST, 1, "Delete", "Global")
add item to list(%LIST, 2, "Delete", "Global")
thread {
    set(#LIST Local, $Function(), "Global")
}
define $Function {
    clear list(%LIST)
    add item to list(%LIST, 2, "Delete", "Local")
    if($true) {
        then {
        }
        else {
            clear list(%LIST)
        }
    }
    return(%LIST)
}

CONCLUSION:

Global list "%LIST" (which can be seen in debugger) is actually cleared  when "$Function" is ran, and that local list really holds value 2, since it gets returned to variable "#LIST Local".

why it is not working when you change the function to command?

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...