Jump to content
UBot Underground

Thread Heaven Thread Hell


Recommended Posts

I decided to test out the thread command.

 

When I run the script below it seems to work okay. Watching the Debug window show the #i variable is the same as the %zlist list.

But, when I run script several times in quick succession I notice some time there is a discrepancy See the attached image.

 

As you can see the code is very simple so there doesn't seem to be much room for error, but obviously I am doing something wrong, somewhere .... OR ... is it that the thread command isn't working right?

clear list(%zlist)
set(#i, 0, "Global")
loop(20) {
    loop(5) {
        runMe(#i)
        increment(#i)
    }
}
define runMe(#counter) {
    thread {
        add item to list(%zlist, #counter, "Don\'t Delete", "Global")
    }
}

http://content.screencast.com/users/Pete_1/folders/Jing/media/051781f7-2279-4e87-9bad-9bfa7bc1eb6d/2014-08-31_1801.png

 

http://screencast.com/t/XnitPGSGoh

Link to post
Share on other sites

Thanks for the info Kev. I'll check it out.

 

I've noticed similar issues when writing out to a file when not using lists too.

set(#i, 0, "Global")
loop(10) {
    loop(15) {
        runMe(#i)
        increment(#i)
    }
}
define runMe(#counter) {
    thread {
        set(#gotPage, "{#counter} - QWERTY
", "Local")
        append to file("{$special folder("Desktop")}\\thread.txt", #gotPage, "End")
    }
}

Is this down to the THREAD command not working correctly or something else? Was thinking may be down to the APPEND TO FILE command. If one thread is already appending to the file when another thread tries to write, what happens? Does it just fail with no error message?

 

Thanks,

Pete

Link to post
Share on other sites

Thanks for the info Kev. I'll check it out.

 

I've noticed similar issues when writing out to a file when not using lists too.

set(#i, 0, "Global")
loop(10) {
    loop(15) {
        runMe(#i)
        increment(#i)
    }
}
define runMe(#counter) {
    thread {
        set(#gotPage, "{#counter} - QWERTY
", "Local")
        append to file("{$special folder("Desktop")}\\thread.txt", #gotPage, "End")
    }
}

Is this down to the THREAD command not working correctly or something else? Was thinking may be down to the APPEND TO FILE command. If one thread is already appending to the file when another thread tries to write, what happens? Does it just fail with no error message?

 

Thanks,

Pete

its down to two threads trying to write at the same time causing loss of data. I wouldn't recommend using the append to file from a thread. create the data first in say a list then save to file once all is complete

  • Like 1
Link to post
Share on other sites

Also writing data at such rate could be overloading your disk drive (especially HDD), since in your case you are writing to disk every few hundred millisecond (less than a second between writes)... so it's another reason to save data outside threads.

  • Like 1
Link to post
Share on other sites

Yep, I figured it must have been something to do with the append. That's actually what got me to try a list and watch in debug mode. From one issue to another :)

 

So for this example do you recommend saving the data to a Large List (your plugin Kev) while in a thread and then processing the data once all threads are complete? I take it there shouldn't be any problem writing to the same list in multiple threads at the same time?

Link to post
Share on other sites

Yep, I figured it must have been something to do with the append. That's actually what got me to try a list and watch in debug mode. From one issue to another :)

 

So for this example do you recommend saving the data to a Large List (your plugin Kev) while in a thread and then processing the data once all threads are complete? I take it there shouldn't be any problem writing to the same list in multiple threads at the same time?

yes do that, no the lists in the large data plugin are designed to be able to be written to from threads so shouldn't be any issues

  • Like 1
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...