Don't click here unless you want to be banned.

LSL Wiki : multithreading

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are


Multithreading can be used to pass delayed tasks to other scripts by link messages.

Warning: The practice of multithreading to eliminate script delays is a mildly dangerous one at best, and holds the potential to bring a server to its knees, or outright crash it at its worst. Please, for the love of the hippos, try to refrain from multithreading unless it is absolutely necessary for a script to have no script delay. A multithreaded script can cause problems for dozens or even hundreds of users if done needlessly. Multithreading can cause unnecessary strain on sims or other servers, and should be avoided when possible.

An example of multithreading would be having a script that would need to send an email every time something occured. By using llMessageLinked, another script in the same object could be told to send the email instead, thereby sparing the main script from llEmail's built-in 20-second delay.

Example added by MarcEisenberg:
This is the mailing system script. Only one of these scripts in the linked object hierarchy is necessary:
integer LINKMSG_SEND_EMAIL = 1451363;

default {
    link_message(integer sender_num, integer num, string str, key id) {
        if (num == LINKMSG_SEND_EMAIL) {
            list mailparam_list = llCSV2List(str);
            string mailto_str = llBase64ToString(llList2String(mailparam_list, 0));
            string mailsubj_str = llBase64ToString(llList2String(mailparam_list, 1));
            string mailbody_str = llBase64ToString(llList2String(mailparam_list, 2));
            llEmail(mailto_str, mailsubj_str, mailbody_str);

This is the script that tells the mailing system it needs to email. Include this at the top of any script that will send mail in a linked object hierarchy:
integer LINKMSG_SEND_EMAIL = 1451363;

MT_SendEmail(string mailto_str, string mailsubj_str, string mailbody_str)

Then, messages are sent using this: MT_SendEmail("", "Subject", "This is my message");

The message will be passed off to the mail-handling script.

IMPORTANT! Please note that this example uses the number field in the linked messages as an identifier for the type of message. If there are scripts in a linked object that send messages in another way, this script's link handling will need to be modified to match (or there may be problems with miscommunications between objects).

Communications Jasa SEO Jasa SEO Murah Sepatu Online Toko Sepatu Online Sepatu Sepatu Murah Sepatu Safety Sepatu Futsal Cheapes Hostgator Coupon Link Booking Televisori offerte Notebook Offerte Berita Terkini Internet Marketer Muda Internet Marketer Indonesia Portatile Apple RDAnet Lorks Karikatur Bisnis Modal Kecil Bisnis UKM Berita Terbaru Iklan Baris Jasa SEO Jasa SEO Murah SEO Indonesia Konsultan SEO SEO Belajar SEO Kursus SEO Kursus SEO Murah Jam Tangan Casio Jam Tangan Casio Jam Tangan Murah Jam Tangan Grosir Baju Terbaru Grosir Baju Baju Terbaru Grosir Baju Murah Bisnis Online Belajar SEO Kerupuk Kerupuk kulit Social Bookmark Dofollow Social Bookmark Kumpulan Puisi Kirim Puisi bola hantu Penumbuh Rambut Penumbuh Rambut timbangan WBC Wonogiri Jasa SEO Murah Jasa SEO Jam Tangan Murah
Comments [Hide comments/form]
The llList2CSV adds a space after the comma, something you have to take into account for when splitting with llParseString2List, otherwise the base64 transform will fail. I've added that extra space in the example.
-- PierreJosephProudhon (2006-05-04 22:11:18)
... you don't use llParseString2List to read CSV's back into a list, you would use llCSV2List
-- BlindWanderer (2006-05-05 15:39:20)
Er, why did you remove the task link, Chris?
-- EepQuirk (2006-05-06 01:42:10)
Please visit what you link to before you link to it. "task" how you used it was significantly different from the "task" referred to by the task page. (It doesn't make sense if you read the sentence, click on the task link and read the task page.) I recommend adding information disambiguating the two meanings of "task" on the task page before you link there from here.
-- ChristopherOmega (2006-05-06 19:00:54)
Feel free to add it yourself, too...
-- EepQuirk (2006-05-07 15:28:28)
It might be nice to have a real discussion about when and when not to use this kind of multithreading. I want to have a client/server system, with a notecard-based server, and objects talking to each other via llregionsay. Should the whole thing slow down and stop while the server object reads a notecard?

Also, it seems reasonable to make generalized notecard-reading scripts and then have them broadcast their news via link or chat. Is this a harmful use of multithreading?
-- (2007-12-29 09:55:53)