This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Localbus COPAS Bug: Multithreading Issue with 2 Thread Levels
#1
Description:
I am encountering an issue with my Lua script. The problem is illustrated here with a simplified version to expose the general architecture, but it's in my more complex and extensive code that the bug manifests. During increased CPU load, the complete script seems to enter an infinite loop with CPU usage exceeding 100%, specifically stalling on the 'copas.step()' instruction.

Context:
This ticket presents a simplified version of the code to illustrate the architecture and facilitate discussion. However, the problem occurs in the larger and complete version of the script.

Code snippet (simplified for illustration):
Code:
if not client then
  client = require('localbus').new(0.1)

  function eventhandler(event)
    local eventObject = grp.find(event.dst)
    eventObject.data = knxdatatype.decode(event.datahex, eventObject.datatype)
    copas.addthread(function()
      log("first thread launching other threads")
      -- do some stuff
      copas.addthread(function()
        log("second level thread 1")
        -- do some stuff
      end)
      copas.addthread(function()
        log("second level thread 2")
        -- do some stuff
      end)
    end)
  end

  client:sethandler('groupwrite', eventhandler)
end

log("bug lb")
client:loop(1)
log("bug copas")
copas.step()

[Image: Microsoft-Teams-image-29.png]

Problem Encountered:

High CPU usage and entering an infinite loop in the complete version of the script during periods of load.
Specific stalling on the 'copas.step()' instruction.

Impact:
This situation completely blocks the operation of the script.

Request:
I am seeking assistance to diagnose and resolve this issue in the context of the complete version of my script. Advice on the general architecture as well as specific suggestions to avoid this kind of stalling would be extremely useful.
Reply


Messages In This Thread
Localbus COPAS Bug: Multithreading Issue with 2 Thread Levels - by Blooddah - 21.12.2023, 13:43

Forum Jump: