Re: Phix: Understanding Multithreading

new topic     » goto parent     » topic index » view thread      » older message » newer message

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 dx=1 to length(dxoetc) do 
                    if fi=dxoetc[dx] then 
                        fidx = dx 
                        exit 
                    end if 
                end for 
 
--              or (showcommas and find(fi,"df")=0) then 
                or (showcommas and fi!='d' and fi!='f') then 

EDIT: oops, i ==> dx
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.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu