diff --git a/README.html b/README.html index b06c853..eb7824c 100644 --- a/README.html +++ b/README.html @@ -9,7 +9,7 @@
-NOTE: I have been studying a lot about threading in the past few weeks and have some awesome additions in store! They will take a while to come out though. The goal of the library is still to provide a simple and efficient way to multi task in lua
Upcoming Plans: Adding network support for threading. Kinda like your own lua cloud. This will require the bin, net, and multi library. Once that happens I will include those libraries as a set. This also means that you can expect both a stand alone and joined versions of the libraries.
In Changes you’ll find documentation for(In Order):
NOTE: I have been studying a lot about threading in the past few weeks and have some awesome additions in store! They will take a while to come out though. The goal of the library is still to provide a simple and efficient way to multi task in lua
Upcoming Plans: Adding network support for threading. Kinda like your own lua cloud. This will require the bin, net, and multi library. Once that happens I will include those libraries as a set. This also means that you can expect both a stand alone and joined versions of the libraries.
In Changes you’ll find documentation for(In Order):
My multitasking library for lua. It is a pure lua binding if you ingore the integrations and the love2d compat. If you find any bugs or have any issues please let me know :). If you don’t see a table of contents try using the ReadMe.html file. It is eaiser to navigate the readme
For real-time assistance with my libraries! A place where you can ask questions and get help with any of my libraries. Also you can request features and stuff there as well.
https://discord.gg/U8UspuA
In regards to integrations, thread cancellation works slightly different for love2d and lanes. Within love2d I was unable to (To lazy to…) not use the multi library within the thread. A fix for this is to call multi:Stop() when you are done with your threaded code! This may change however if I find a way to work around this. In love2d in order to mimic the GLOBAL table I needed the library to constantly sync tha data… You can use the sThread.waitFor(varname), or sThread.hold(func) methods to sync the globals, to get the value instead of using GLOBAL and this could work. If you want to go this route I suggest setting multi.isRunning=true to prevent the auto runner from doing its thing! This will make the multi manager no longer function, but thats the point :P
Another bug concerns the SystemThreadedJobQueue, Only 1 can be used for now… Creating more may not be a good idea.
And systemThreadedTables only supports 1 table between the main and worker thread! They do not work when shared between 2 or more threads. If you need that much flexiblity ust the GLOBAL table that all threads have.
For module creators using this library. I suggest using SystemThreadedQueues for data transfer instead of SystemThreadedTables for rapid data transfer, If you plan on having Constants that will always be the same then a table is a good idea! They support up to n threads and can be messed with and abused as much as you want :D
Love2D SystemThreadedTAbles do not send love2d userdata, use queues instead for that!
Add system threads for love2d that works like the lanesManager (loveManager, slight differences).In regards to integrations, thread cancellation works slightly different for love2d and lanes. Within love2d I was unable to (To lazy to…) not use the multi library within the thread. A fix for this is to call multi:Stop() when you are done with your threaded code! This may change however if I find a way to work around this. In love2d in order to mimic the GLOBAL table I needed the library to constantly sync tha data… You can use the sThread.waitFor(varname), or sThread.hold(func) methods to sync the globals, to get the value instead of using GLOBAL and this could work. If you want to go this route I suggest setting multi.isRunning=true to prevent the auto runner from doing its thing! This will make the multi manager no longer function, but thats the point :P
Another bug concerns the SystemThreadedJobQueue, Only 1 can be used for now… Creating more may not be a good idea.
And systemThreadedTables only supports 1 table between the main and worker thread! They do not work when shared between 2 or more threads. If you need that much flexiblity ust the GLOBAL table that all threads have.
For module creators using this library. I suggest using SystemThreadedQueues for data transfer instead of SystemThreadedTables for rapid data transfer, If you plan on having Constants that will always be the same then a table is a good idea! They support up to n threads and can be messed with and abused as much as you want :D
Love2D SystemThreadedTAbles do not send love2d userdata, use queues instead for that!
function<
end
end)
multi:mainloop()
-Looping…
Looping…
Looping…
Looping…
Looping…
Looping…
Looping…
Looping…
Looping…
Loop timed out! tloop Trying again…
Looping…
Looping…
Looping…
Looping…
Looping…
We did it! 1 2 3
Added:
Looping…
Looping…
Looping…
Looping…
Looping…
Looping…
Looping…
Looping…
Looping…
Loop timed out! tloop Trying again…
Looping…
Looping…
Looping…
Looping…
Looping…
We did it! 1 2 3
Update: 1.9.1
Added:
Integration “multi.integration.luvitManager”
Limited… Only the basic multi:newSystemThread(…) will work
Not even data passing will work other than arguments… If using the bin library you can pass tables and function… Even full objects as long as inner recursion is not preasent.
Updated:
multi:newSystemThread(name,func,…)
It will not pass the … to the func()
Do not know why this wasn’t done in the first place :P
Also multi:getPlatform(will now return “luvit” if using luvit… Though Idk if module creators would use the multi library when inside the luvit enviroment
Added:
Works on threads and regular objects. Requires the latest bin library to work!
"
c.thread=love.thread.newThread(multi.integration.love2d.ThreadBase:gsub("INSERT_USER_CODE",dump(func)))
- c.thread:start(c.ID,c.name)
+ c.thread:start(c.ID,c.name,...)
function c:kill()
multi.integration.GLOBAL["__DIEPLZ"..self.ID.."__"]="__DIEPLZ"..self.ID.."__"
end
diff --git a/multi/integration/luvitManager.lua b/multi/integration/luvitManager.lua
new file mode 100644
index 0000000..04af6c9
--- /dev/null
+++ b/multi/integration/luvitManager.lua
@@ -0,0 +1,126 @@
+--[[
+MIT License
+
+Copyright (c) 2017 Ryan Ward
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+]]
+
+-- I DEMAND USAGE FOR LUVIT
+-- Cannot use discordia without my multitasking library (Which I love more that the luvit platform... then again i'm partial :P)
+package.path="?/init.lua;?.lua;"..package.path
+local function _INIT(luvitThread,timer)
+ -- lots of this stuff should be able to stay the same
+ function os.getOS()
+ if package.config:sub(1,1)=='\\' then
+ return 'windows'
+ else
+ return 'unix'
+ end
+ end
+ -- Step 1 get setup threads on luvit... Sigh how do i even...
+ require("multi")
+ function multi:canSystemThread()
+ return true
+ end
+ function multi:getPlatform()
+ return "luvit"
+ end
+ local multi=multi
+ -- Step 2 set up the Global table... is this possible?
+ local GLOBAL={}
+ setmetatable(GLOBAL,{
+ __index=function(t,k)
+ --print("No Global table when using luvit integration!")
+ return nil
+ end,
+ __newindex=function(t,k,v)
+ --print("No Global table when using luvit integration!")
+ end,
+ })
+ local THREAD={}
+ function THREAD.set(name,val)
+ --print("No Global table when using luvit integration!")
+ end
+ function THREAD.get(name)
+ --print("No Global table when using luvit integration!")
+ end
+ local function randomString(n)
+ local str = ''
+ local strings = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','1','2','3','4','5','6','7','8','9','0','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'}
+ for i=1,n do
+ str = str..''..strings[math.random(1,#strings)]
+ end
+ return str
+ end
+ function THREAD.waitFor(name)
+ --print("No Global table when using luvit integration!")
+ end
+ function THREAD.testFor(name,val,sym)
+ --print("No Global table when using luvit integration!")
+ end
+ function THREAD.getCores()
+ return THREAD.__CORES
+ end
+ if os.getOS()=="windows" then
+ THREAD.__CORES=tonumber(os.getenv("NUMBER_OF_PROCESSORS"))
+ else
+ THREAD.__CORES=tonumber(io.popen("nproc --all"):read("*n"))
+ end
+ function THREAD.kill() -- trigger the thread destruction
+ error("Thread was Killed!")
+ end
+ -- hmmm if im cleaver I can get this to work... but since data passing isn't going to be a thing its probably not important
+ function THREAD.sleep(n)
+ --print("No Global table when using luvit integration!")
+ end
+ function THREAD.hold(n)
+ --print("No Global table when using luvit integration!")
+ end
+ -- Step 5 Basic Threads!
+ local function entry(path,name,func,...)
+ local timer = require'timer'
+ local luvitThread = require'thread'
+ package.path=path
+ loadstring(func)(...)
+ end
+ function multi:newSystemThread(name,func,...)
+ local c={}
+ local __self=c
+ c.name=name
+ c.Type="sthread"
+ c.thread={}
+ c.func=string.dump(func)
+ function c:kill()
+ -- print("No Global table when using luvit integration!")
+ end
+ luvitThread.start(entry,package.path,name,c.func,...)
+ return c
+ end
+ print("Integrated Luvit!")
+ multi.integration={} -- for module creators
+ multi.integration.GLOBAL=GLOBAL
+ multi.integration.THREAD=THREAD
+ require("multi.integration.shared")
+ -- Start the main mainloop... This allows you to process your multi objects, but the engine on the main thread will be limited to .001 or 1 millisecond sigh...
+ local interval = timer.setInterval(1, function ()
+ multi:uManager()
+ end)
+end
+return {init=function(threadHandle,timerHandle) _INIT(threadHandle,timerHandle) return GLOBAL,THREAD end}