UBotDev 276 Posted November 27, 2013 Author Report Share Posted November 27, 2013 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 ). Quote Link to post Share on other sites
mamica 10 Posted January 3, 2014 Report Share Posted January 3, 2014 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? Quote Link to post Share on other sites
UBotDev 276 Posted January 3, 2014 Author Report Share Posted January 3, 2014 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/ Quote Link to post Share on other sites
Sanjeev 46 Posted January 4, 2014 Report Share Posted January 4, 2014 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. Quote Link to post Share on other sites
UBotDev 276 Posted January 4, 2014 Author Report Share Posted January 4, 2014 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. Quote Link to post Share on other sites
Sanjeev 46 Posted January 4, 2014 Report Share Posted January 4, 2014 Good to hear that.Thanks UbotDev! Quote Link to post Share on other sites
UBotDev 276 Posted January 4, 2014 Author Report Share Posted January 4, 2014 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 Quote Link to post Share on other sites
mamica 10 Posted January 5, 2014 Report Share Posted January 5, 2014 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? Quote Link to post Share on other sites
UBotDev 276 Posted January 5, 2014 Author Report Share Posted January 5, 2014 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. Quote Link to post Share on other sites
Security 17 Posted January 5, 2014 Report Share Posted January 5, 2014 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. Quote Link to post Share on other sites
UBotDev 276 Posted January 6, 2014 Author Report Share Posted January 6, 2014 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. Quote Link to post Share on other sites
Sanjeev 46 Posted January 6, 2014 Report Share Posted January 6, 2014 @UbotDev - I totally agree with @Security. Thank you so much for your support and help. Quote Link to post Share on other sites
UBotDev 276 Posted January 6, 2014 Author Report Share Posted January 6, 2014 @UbotDev - I totally agree with @Security. Thank you so much for your support and help.Thanks again, I'm glad I can help. Quote Link to post Share on other sites
Security 17 Posted January 8, 2014 Report Share Posted January 8, 2014 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.. Quote Link to post Share on other sites
UBotDev 276 Posted January 9, 2014 Author Report Share Posted January 9, 2014 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. Quote Link to post Share on other sites
Sanjeev 46 Posted January 9, 2014 Report Share Posted January 9, 2014 Thanks @Security! Quote Link to post Share on other sites
Sanjeev 46 Posted January 23, 2014 Report Share Posted January 23, 2014 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. Quote Link to post Share on other sites
UBotDev 276 Posted January 23, 2014 Author Report Share Posted January 23, 2014 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. Quote Link to post Share on other sites
Sanjeev 46 Posted January 23, 2014 Report Share Posted January 23, 2014 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! Quote Link to post Share on other sites
UBotDev 276 Posted January 23, 2014 Author Report Share Posted January 23, 2014 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. Quote Link to post Share on other sites
Sanjeev 46 Posted January 23, 2014 Report Share Posted January 23, 2014 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 ... Quote Link to post Share on other sites
UBotDev 276 Posted January 23, 2014 Author Report Share Posted January 23, 2014 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. Quote Link to post Share on other sites
Sanjeev 46 Posted January 23, 2014 Report Share Posted January 23, 2014 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 commandare 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. Quote Link to post Share on other sites
UBotDev 276 Posted January 23, 2014 Author Report Share Posted January 23, 2014 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 commandare 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. Quote Link to post Share on other sites
Sanjeev 46 Posted January 24, 2014 Report Share Posted January 24, 2014 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! Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.