forum-msg-id-133933-edit

Original date:2019-06-03 13:36:00 Edited by: petelomax Subject: Re: Phix: Understanding Multithreading

When using multithreading, shared reference counts (especially the hidden ones on literal constants) are a real pita.

The problem you hit is builtins/VM/pprntfN.e, aka sprintf(), is not thread safe - I have just made the following (yet more) fixes to it:

--                  result = "1"&result 
                    result = '1'&result 
                else 
--                  result = "-1"&result[2..$] 
                    result = '-'&'1'&result[2..$] 
 
--          reve = "0" 
            reve = repeat('0',1) 
 
--                      if find(result,{"","-","+"}) then 
                        if length(result)=0 
                        or (length(result)=1 and (result[1]='-' or result[1]='+')) then 
 
--string hexchar 
string hexchar, dxoetc 
 
            hexchar = "0123456789ABCDEFabcdef" 
            dxoetc = "dxobscvefgEXG" 
 
--              fidx = find(fi,"dxobscvefgEXG") 
                fidx = 0 
                for i=1 to length(dxoetc) do 
                    if fi=dxoetc[i] then 
                        fidx = i 
                        exit 
                    end if 
                end for 
 
--              or (showcommas and find(fi,"df")=0) then 
                or (showcommas and fi!='d' and fi!='f') then 

As you say though, that enter_cs()/leave_cs() is a perfectly fine way to deal with it as well, and the above is for educational purposes only.

I suppose multithreading is a bit like working for MI6 or the NSA - you have to be really paranoid about privacy. Ideally you should do the absolute bare minimum work in the thread itself, and pass the results back to the main thread for any printing/logging/storing, etc.

Not Categorized, Please Help

Search



Quick Links

User menu

Not signed in.

Misc Menu