Jump to content
UBot Underground

[FREE PLUGIN] Threads Counter - UBot v4 Threading Fixed


Recommended Posts

Waiting for the answer :-)

 

I've got the answer from support but it doesn't explain the problem, since they were not able to reproduce that in v4. :/

 

However, they said that programer can look into that, but he is very busy...so I said that they should leave that and rather work on v5 and threading problem there: http://tracker.ubotstudio.com/issues/208

 

That's why I suggest you use "stop" command at the end of the script as workaround for problems in v4 (btw, I've tested the same code in v5 and it  seems to work there OK ).

Link to post
Share on other sites
  • 1 month later...
  • Replies 160
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

As you may be aware threading in UBot v4 is not safe and may not work as expect under certain conditions, which would result in threads slowly dying out, so at the end, you only get left with 1 active

Awesome plugin UBotDev

You are not using the plugin from the title, instead you are using the plugin that Blumi 40 keeps posting here (Blumi40, can you please open another thread for that plugin instead of discussing it her

Can we "noobs" know how to use this plugin?

 

I installed it and copy pasted that example code. And i see all stuff, but how do i for example send mass emails with threads? Or surf list of pages in threads.

 

Where do i need to put my code?

Link to post
Share on other sites

Can we "noobs" know how to use this plugin?

 

I installed it and copy pasted that example code. And i see all stuff, but how do i for example send mass emails with threads? Or surf list of pages in threads.

 

Where do i need to put my code?

The threading code with this plugin or without is very similar, this plugin only provides a thread counter which will allow you faster/proper threading.

 

Well, first you need to prepare "send mass emails"/"surf list of pages" code, and when you have that one working, you place that code into a define command (don't forget to use local variables!) and you call that command from inside THREAD START->thread (from line number 26 for example: http://ubotdev.com/free-plugin-threads-counter#ubot-threading-example).

 

Hope that helps.

 

Btw, I noticed that Gogetta released some free code which uses this plugin, so you could also check that as an example: http://www.ubotstudio.com/forum/index.php?/topic/15698-free-super-fast-proxy-checker-socketsthreaded-source-code/

Link to post
Share on other sites

Hi UbotDev -

While using your threading plugin , would you recommend the Local dictionary plugin be used instead of the normal set command for setting variables to local ?

Thanks.

Link to post
Share on other sites

Hi UbotDev -

While using your threading plugin , would you recommend the Local dictionary plugin be used instead of the normal set command for setting variables to local ?

Thanks.

I think you are good with UBot local variables, but you can also use "local dictionary" if you want.

Link to post
Share on other sites

I noticed that a lot of people has hard times implementing threading with UBot, that's why I decided to provide another example:

http://www.ubotstudio.com/forum/index.php?/topic/15441-free-plugin-threads-counter-ubot-v4-threading-fixed/&do=findComment&comment=87936

Link to post
Share on other sites

Ok great, thanks. But can you tell me what is input count? I see when it hits zero bot stops. So is this some kind of loop limit?

 

And what do you mean by setting variables to local. I use define command and then call inside the thread a custom command. So i need to set variables in my define to local?

Link to post
Share on other sites

Ok great, thanks. But can you tell me what is input count? I see when it hits zero bot stops. So is this some kind of loop limit?

 

And what do you mean by setting variables to local. I use define command and then call inside the thread a custom command. So i need to set variables in my define to local?

COUNT variable is from the previous example (it was set from UI there), that's why I haven't changed it's name. Yes, COUNT tells UBot how many times it should loop/how many items there are to process.

 

By setting variables to local I mean that define commands that are called from inside the thread should have most of variables local, so that 2 or more defines can run side by side, without effecting each other. I usually only have 2 global variables inside thread and they are global status and threads counter.

Link to post
Share on other sites

This is a great contribution. Especially all the documentation and how actively you offer support on these threads. I don't know where ubot would be if not for people like you, thanks a lot.

Link to post
Share on other sites

This is a great contribution. Especially all the documentation and how actively you offer support on these threads. I don't know where ubot would be if not for people like you, thanks a lot.

Thanks for the kind words, it's really nice and encouraging to hear them.

Link to post
Share on other sites

Hi UbotDev -

While using your threading plugin , would you recommend the Local dictionary plugin be used instead of the normal set command for setting variables to local ?

Thanks.

I would recommend using this plugin along with Aymen's dictionary plugin.  I was using it separately, after about 9 + hours of running with only 8 threads i notice local variables bleeding into each other messing everything up. Once i used Aymen's plugin along with "Thread counter" things have been running perfectly..

Link to post
Share on other sites

I would recommend using this plugin along with Aymen's dictionary plugin.  I was using it separately, after about 9 + hours of running with only 8 threads i notice local variables bleeding into each other messing everything up. Once i used Aymen's plugin along with "Thread counter" things have been running perfectly..

Nice to hear, thanks for reporting back.

Link to post
Share on other sites
  • 2 weeks later...

Hello UbotDev,


Could you please tell me when do we need to use the 'read' option of your Threads Counter Plugin?

In your first example code - I find-

----------------------------------------------------------------------

1. loop while($comparison(#COUNT, ">", 0)) {
    if($comparison(#THREADS Active, "<", #THREADS Max)) {
        then {.......

----------------------------------------------------------------------

2. loop while($comparison(#THREADS Active, ">", 0)) {
    set(#THREADS Active, $plugin function("Threads Counter.dll", "threads counter", "read"), "Global")
    wait(2)
}
----------------------------------------------------------------------
In the 1st case - every time the loop condition needs to  be tested - you are not explicitly reading the value of '#THREADS Active' via Plugin's -"read" parameter .

But later while checking if all threads are closed -> you do use "read"  to  get the current value? of #THREADS Active.
why is that?

Thanks.

Link to post
Share on other sites

Hello UbotDev,

 

 

Could you please tell me when do we need to use the 'read' option of your Threads Counter Plugin?

 

In your first example code - I find-

 

----------------------------------------------------------------------

 

1. loop while($comparison(#COUNT, ">", 0)) {

    if($comparison(#THREADS Active, "<", #THREADS Max)) {

        then {.......

 

----------------------------------------------------------------------

 

2. loop while($comparison(#THREADS Active, ">", 0)) {

    set(#THREADS Active, $plugin function("Threads Counter.dll", "threads counter", "read"), "Global")

    wait(2)

}

----------------------------------------------------------------------

In the 1st case - every time the loop condition needs to  be tested - you are not explicitly reading the value of '#THREADS Active' via Plugin's -"read" parameter .

 

But later while checking if all threads are closed -> you do use "read"  to  get the current value? of #THREADS Active.

why is that?

 

Thanks.

Actually I've made a mistake (not sure how I missed that), so I have just modified the code to fix that. :$ Nice catch.

 

To answer your question, we should always use plugins read command if we are not setting variable #THREADS Active inside loop, so that we always get the freshest counter value.

 

Thanks for reporting this.

Link to post
Share on other sites

Hi UbotDev,

 

Thanks for your prompt reply.

 

To answer your question, we should always use plugins read command if we are not setting variable #THREADS Active inside loop, so that we always get the freshest counter value.

I'm sorry, I didn't get it :(

 

Also - I find that you do not use local variables any where inside the threads.. Is that really nonessential then..?

Just wanted to know.. No pointing of me breaking my head over setting local variables inside threads if they are a waste of time.

 

Also -why are you passing global variables from one command to another? Do global variables also need to be passed? can't they just be read from anywhere within the script?

 

Thanks!

Link to post
Share on other sites

Hi UbotDev,

 

Thanks for your prompt reply.

I'm sorry, I didn't get it :(

 

Also - I find that you do not use local variables any where inside the threads.. Is that really nonessential then..?

Just wanted to know.. No pointing of me breaking my head over setting local variables inside threads if they are a waste of time.

 

Also -why are you passing global variables from one command to another? Do global variables also need to be passed? can't they just be read from anywhere within the script?

 

Thanks!

With previous code we didn't check the number of loops frequently enough, that's why I changed the code (it's safer to just get counter value via plugin->read, rather than reading that from a UBot variable that was set in sometime in the past).

 

I don't use local variables directly because the code that is there doesn't need any additional local variables. You should also notice that I'm passing a global variable into a define command as parameter, which actually makes it local variable inside that define command (so I actually use local variables like that). It may be confusing to you because they have the same name, but actually once you pass the variable in define it becomes local variable.

 

Hope that helps you.

Link to post
Share on other sites

 Thanks for The reply.

 

 

You should also notice that I'm passing a global variable into a define command as parameter, which actually makes it local variable inside that define command (so I actually use local variables like that).

 

I guess it's back to Ubot kindergarten for me ...  :)

Link to post
Share on other sites

 Thanks for The reply.

 

 

I guess it's back to Ubot kindergarten for me ...  :)

Hehe :) To get you up to primary school I'm going to further explain: whenever you have some data outside of the thread/define (THREAD START define in my example) and you want to pass that into a thread, you would do that with define command + parameter (containing that data). You would do so because in such way you can re-use the same define command, which with different parameters allows you to run multiple threads with one/that define command (I guess you knew that). However, the parameters that are sent in to the define/thread are there represented as local variable, so that each thread has its own data (one thread doesn't read anothers data, that's why we pass data in as parameter to avoid that).

 

You should also know that you should always have a define command (with parameters passed in) around the thread command (again refer to THREAD START); if we wouldn't do that variables #PROXIES ROW and  #RESULTS ROW" would change the values before the thread would end, meaning that some parts of the current thread would be using wrong data (data from next thread), as soon as those 2 values get changed, which would result in unpredicted behavior and results (this happens because thread is running parallel to the main/UI code, which means that right after UBot start thread command it also executes commands bellow thread; in our case we don't have any code there, so UBot would just try to spawn the next thread with new data parallel to previous thread).

 

I hope you'll find this info useful. ;)

Link to post
Share on other sites

UbotDev,

 

Thanks for taking out the time to share your Knowledge!

 

 

you should also know that you should always have a define command (with parameters passed in) around the thread command (again refer to THREAD START); if we wouldn't do that variables #PROXIES ROW and  #RESULTS ROW" would change the values before the thread would end

 

You mean pass on the global variables required by the thread into defines/functions as parameters - as soon as the thread starts - so the data gets secured - as they get converted to local?

 

If that's what you mean I knew that. What I did not know,(and I now realize in hindsight -that it was quite stupid on my part) is that global variables coming in as parameters via a function or command

are automatically converted to local for that thread.

 

I was under the impression that we needed to then store the passed global variables  as 'local' variables - inside the defines.

 

i.e - if  '#proxies' is a  global variable passed into  a 'command' inside a thread - then I would need to do the following to convert to local--

set(#LocalProxy, "proxies", "Local")

 

Thanks for the clarification.

------------------------------------------------------------
 

But What I do not understand is suppose there are 50 or more threads executing at once - the chances of multiple threads trying to grab the same global data increases.

How do we prevent this from happening?

 

Thanks.

Link to post
Share on other sites

UbotDev,

 

Thanks for taking out the time to share your Knowledge!

 

 

You mean pass on the global variables required by the thread into defines/functions as parameters - as soon as the thread starts - so the data gets secured - as they get converted to local?

 

If that's what you mean I knew that. What I did not know,(and I now realize in hindsight -that it was quite stupid on my part) is that global variables coming in as parameters via a function or command

are automatically converted to local for that thread.

 

I was under the impression that we needed to then store the passed global variables  as 'local' variables - inside the defines.

 

i.e - if  '#proxies' is a  global variable passed into  a 'command' inside a thread - then I would need to do the following to convert to local--

set(#LocalProxy, "proxies", "Local")

 

Thanks for the clarification.

------------------------------------------------------------

 

But What I do not understand is suppose there are 50 or more threads executing at once - the chances of multiple threads trying to grab the same global data increases.

How do we prevent this from happening?

 

Thanks.

Yes for first part, with only difference that you need to pass data before the thread start (not "as soon as the thread starts") and this way "secure" the data as you said.

 

Well if you try to prevent it you would need to reduce the speed/number of threads but that is not a concern; if the global data is only grabbed (I assume you mean read by that) there is no need to worry about it. The problem kicks in when you try to read-process-write to global variable from multiple threads (like we used to do with native UBot decrement command read,increment,write), and this is the case you want to avoid.

Link to post
Share on other sites

 

with only difference that you need to pass data before the thread start

 

Wow ! UbotDev  - this looks like a foolproof approach to threading! I was always used to thinking of commands and functions as being containers to be called from inside of a thread - to isolate local vars from each other/on a per thread basis. - which is correct.

 

But calling a command/function and then initiating a thread from within that define- Not only guarantees that the variables will not be altered by the main thread -but also by succeeding threads!

I guess this clears up all my doubts regarding the following.

 

But What I do not understand is suppose there are 50 or more threads executing at once - the chances of multiple threads trying to grab the same global data increases.

How do we prevent this from happening?

 

--------------------------------------------------------------

You mentioned -

 

The problem kicks in when you try to read-process-write to global variable from multiple threads (like we used to do with native UBot decrement command read,increment,write), and this is the case you want to avoid.

 

So when I write out from a thread it's local values to  a global list/var/table cell - is that write operation - fully  thread safe?

 

Thanks!

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