Jump to content
UBot Underground

Multi thread - read and add list items / tables


Recommended Posts

Hello.

 

I'm currently working on my first project with threads. I'm just wondering if there are any known issues / limitations with threads in ubot studio?

I know about the thread counter glitch. 

 

But what about reading and writing to lists and tables? Is that working correctly? When I use a global list and use $next list item  in my threads? 

Will that work correctly?

 

If you are aware of any other challenges with threads and lists/tables, please let me know.

 

Thanks in advance for your help

Dan

Link to post
Share on other sites

$next list item is the proper way to use it.

 

using any sort of control over the item using a variable you will likely run into  problems

and also cant itterate through a table in multiple threads you will lose the row postioning

 

instead load that table into a list

then use next list item into a list of your multi threading and break it down for use that way

Link to post
Share on other sites

The problem only exists when multiple threads are accessing the same resource and they are performing read-modify-write (like for counter). If you only read or only write to a global variable/list/table you should be OK.

 

I think its saver to use next list item outside threads and rather pass the next list item value to a thread as parameter (maybe even list position).

Link to post
Share on other sites

The problem only exists when multiple threads are accessing the same resource and they are performing read-modify-write (like for counter). If you only read or only write to a global variable/list/table you should be OK.

 

I think its saver to use next list item outside threads and rather pass the next list item value to a thread as parameter (maybe even list position).

Thanks a lot guys. 

 

I have it working perfectly with Lists now.

 

set(#active threads$plugin function("Threads Counter.dll""threads counter""reset"), "Global")

set list position(%userurl, 0)

loop($list total(%userurl)) {

    loop while($comparison($plugin function("Threads Counter.dll""threads counter""read"), ">=", 50)) {

        wait(0.5)

    }

    set(#active threads$plugin function("Threads Counter.dll""threads counter""increment"), "Global")

    filterresults($list position(%userurl), $next list item(%userurl))

}

define filterresults(#nextposition#nextitem) {

    thread {

        comment("THREAD COMMANDS HERE")

        set(#active threads$plugin function("Threads Counter.dll""threads counter""decrement"), "Global")

    }

}

stop script

 

 

It's a lot more reliable when I hand over the list items and list positions to the threads from the main process.

 

 

Now to the next challenge (tables).

 

In my example each row has 15 columns. And all 15 columns are necessary for single site submission. 

My idea is to loop through the rows. Then convert the columns of that row into a list and hand the list over to the thread. Where it's processed via next list item.

 

So that each row has it's own thread in the end. 

 

The only challenge I currently see is that my table cells contain text with multiple lines. 

 

Is that the correct approach? Or how would you handle data from table with threads?

 

Cheers

Dan

Link to post
Share on other sites

Thanks a lot guys. 

 

I have it working perfectly with Lists now.

 

set(#active threads$plugin function("Threads Counter.dll""threads counter""reset"), "Global")

set list position(%userurl, 0)

loop($list total(%userurl)) {

    loop while($comparison($plugin function("Threads Counter.dll""threads counter""read"), ">=", 50)) {

        wait(0.5)

    }

    set(#active threads$plugin function("Threads Counter.dll""threads counter""increment"), "Global")

    filterresults($list position(%userurl), $next list item(%userurl))

}

define filterresults(#nextposition#nextitem) {

    thread {

        comment("THREAD COMMANDS HERE")

        set(#active threads$plugin function("Threads Counter.dll""threads counter""decrement"), "Global")

    }

}

stop script

 

 

It's a lot more reliable when I hand over the list items and list positions to the threads from the main process.

 

 

Now to the next challenge (tables).

 

In my example each row has 15 columns. And all 15 columns are necessary for single site submission. 

My idea is to loop through the rows. Then convert the columns of that row into a list and hand the list over to the thread. Where it's processed via next list item.

 

So that each row has it's own thread in the end. 

 

The only challenge I currently see is that my table cells contain text with multiple lines. 

 

Is that the correct approach? Or how would you handle data from table with threads?

 

Cheers

Dan

Great you solved it. Btw, you don't need to pass in both, list position and list item value, you can only use one.

 

For the table it's much easier to just pass in the row # and read from the table directly, from threads.

 

I think adding strings with new line character(s) to list can be dangerous, since list delimiter is also new line character (I've done a test and once you save list data with new characters you won't be able to import it as it was, it will have more items - not sure if the same goes for reading a list without saving it, haven't tested that out).

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

 

ui stat monitor("Data: "#querytemplate)

ui check box("add 2nd query"#option)

if($comparison(#option"!=""true")) {

    then {

        add item to list(%querylist"how to * bill""Delete""Global")

    }

    else {

        add item to list(%querylist"how to * bill""Delete""Global")

        add item to list(%querylist"how to * game""Delete""Global")

    }

}

add list to list(%list$list from text("a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z"","), "Delete""Global")

set(#threadloop, 0, "Global")

loop($list total(%querylist)) {

    thread {

        set(#thread_query$list item(%querylist#threadloop), "Global")

        set list position(%list, 0)

        loop($list total(%list)) {

            wait(0.5)

            set(#querytemplate"http://suggestqueries.google.com/complete/search?q={#thread_query}&client=toolbar""Global")

            set(#querytemplate$replace(#querytemplate"*"$list item(%list$list position(%list))), "Global")

            alert($list item(%list$list position(%list)))

            set(#nextlistitem$next list item(%list), "Global")

        }

        increment(#threadloop)

    }

}

I run into this problem, when it is inside a thread, the thread will share the list item and position, this result each individual thread lost its position and variable.

 

(i tried to change global to local, but it do not work.)

 

in my example, please run it with the checkbox = false, it will work fine.

 

then clear the variables and run with the checkbox = true

 

can anyone advice on this? thanks a lot :blink:

 

 

 

Link to post
Share on other sites

You need to use define command around thread, to keep variables inside thread set to one value. Currently you don't do that, so right after the thread is launched #thread_query is changed, so 1st thread uses the query of 2nd thread from there on...

  • Like 1
Link to post
Share on other sites

thanks UbotDev, it works after adding a define command.

just for other to see a working example, here is the code:

 

 

ui stat monitor("Data: "#querytemplate)
ui check box("add 2nd query"#option)
if($comparison(#option"!=""true")) {
    then {
        add item to list(%querylist"how to * bill""Delete""Global")
    }
    else {
        add item to list(%querylist"how to * bill""Delete""Global")
        add item to list(%querylist"how to * game""Delete""Global")
    }
}
set(#threadloop, 0, "Global")
loop($list total(%querylist)) {
    set(#thread_query$list item(%querylist#threadloop), "Global")
    thread {
        process()
    }
    increment(#threadloop)
}
define process {
    in new browser {
        clear list(%list)
        add list to list(%list$list from text("a,b,c,d"","), "Delete""Local")
        set list position(%list, 0)
        loop($list total(%list)) {
            wait(0.5)
            set(#querytemplate#thread_query"Local")
            alert("query template 1: {#querytemplate}")
            set(#querytemplate$replace(#querytemplate"*"$list item(%list$list position(%list))), "Local")
            alert(#querytemplate)
            set(#html2$plugin function("HTTP post.dll""$http get""http://suggestqueries.google.com/complete/search?q={#querytemplate}&client=toolbar"""""""""), "Local")
            alert(#html2)
            set(#nextlistitem$next list item(%list), "Local")
        }
    }
}

Link to post
Share on other sites

You only need a delay between threads as a workaround for UBot bug...instead you can also use my free Threads Counter plugin which solves the threading problem.

 

Also, there is no need to to set it to a new variable once it's passed into the define command, because it is already declared as local variable at that point.

 

Also, you should refer to a newer topic instead, where I explain why that error happened: http://www.ubotstudio.com/forum/index.php?/topic/15122-must-read-threading-doesnt-work-as-expected-tested-in-v4/

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...