Jump to content



Photo

Thread-Safe Deletion From A Global List

lists threading

  • Please log in to reply
3 replies to this topic

#1 drewness

drewness

    Advanced Member

  • Members
  • PipPipPip
  • 89 posts
  • OS:Windows 10
  • Total Memory:More Than 9Gb
  • Framework:v4.5+, unsure
  • License:Developer Edition

Posted 22 September 2017 - 11:31 AM

Hi there,
 
I'm trying to figure out how to handle proxies in my multithreaded bot.
 
Right now, there's a master list of search terms it uses, and a master list of proxies it pulls from. For the search terms it pulls, it's using standard threading and next list item, and for the proxy grabbing it uses a random proxy from the master list.
 
Everything works great for the  most part, but now I'm trying to figure out how to handle bad/blocked proxies.
 
I had originally tried copying a the global Master Proxy List to a local list inside the thread, pulling a random proxy from that list, trying to use it, and checking the results.
 
If it passed, great, it carries on.
 
If it fails, I want to have it pull that proxy from the master list so that other threads don't continually try to use bad proxies and slow the bot down.
 
I tried adding this code in (found in another thread, modified to use Local instead of Global since it's inside a thread):
 
set(#stopme, 0, "Local")
set(#pos, 0, "Local")
loop while($comparison(#stopme, "=", 0)) {
    if($comparison($list item(%masterProxyList, #pos), "=", #currentProxy)) {
        then {
            remove from list(%test, #pos)
            set(#stopme, 1, "Local")
        }
        else {
            increment(#pos)
        }
    }
}
 
However, if two threads fail with two different proxies simultaneously, the master list would be changed by one thread deleting the offending proxy before the other does, which would then mess up the position of 2nd bad proxy the bot is trying to delete, which results in either the bot deleting the wrong proxy or getting an out of bounds error (if it tries to delete the proxy from the 8th position when there's only 7 left after the other thread deletes, for example).
 
I'm trying to wrap my head around how to best tackle a thread-safe global list that threads can delete specified proxies from, and this is my best idea, but I may be barking up the wrong tree as far as execution goes.
 
Any ideas, thoughts, or code examples would be immensely helpful.
 
Thanks in advance for your time!


#2 HelloInsomnia

HelloInsomnia

    Advanced Member

  • Moderators
  • 2803 posts
  • OS:Windows 10
  • Total Memory:More Than 9Gb
  • Framework:v4.5+, unsure
  • License:Developer Edition

Posted 22 September 2017 - 05:24 PM

This plugin has a thread lock that you could use: http://network.ubots...-ini-clipboard/



#3 drewness

drewness

    Advanced Member

  • Members
  • PipPipPip
  • 89 posts
  • OS:Windows 10
  • Total Memory:More Than 9Gb
  • Framework:v4.5+, unsure
  • License:Developer Edition

Posted 22 September 2017 - 06:00 PM

This plugin has a thread lock that you could use: http://network.ubots...-ini-clipboard/

Awesome thank you, I have that plugin but I don't have any experience with thread locking and updating a global list so I think I'll need to go through that thread and hopefully someone has discussed using thread locking, as I'm not sure where to even start with that lol

Thank you for pointing me in the right direction!

Sent from my SAMSUNG-SM-N920A using Tapatalk

#4 HelloInsomnia

HelloInsomnia

    Advanced Member

  • Moderators
  • 2803 posts
  • OS:Windows 10
  • Total Memory:More Than 9Gb
  • Framework:v4.5+, unsure
  • License:Developer Edition

Posted 23 September 2017 - 11:57 AM

Awesome thank you, I have that plugin but I don't have any experience with thread locking and updating a global list so I think I'll need to go through that thread and hopefully someone has discussed using thread locking, as I'm not sure where to even start with that lol

Thank you for pointing me in the right direction!

Sent from my SAMSUNG-SM-N920A using Tapatalk

 

I haven't used that plugin much so you will have to test this but I believe all you need to do is use the lock command right before your thread safe operation then call unlock after it like this:

thread {
    comment("Do whatever you need in your thread.")
    divider
    plugin command("HeopasCustom.dll", "Heopas Thread Lock", "")
    comment("Thread safe operation goes here")
    plugin command("HeopasCustom.dll", "Heopas Thread Unlock")
}






Also tagged with one or more of these keywords: lists, threading

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users