What is data?
Love threads?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Love threads?
http://love2d.org/wiki/love.thread.newThread
Data and files are the only things accepted.
What is data?
What is data?
Last edited by zac352 on Sat Oct 16, 2010 1:07 am, edited 1 time in total.
Hello, I am not dead.
Re: Love threads?
So what? Is this a question? Statement? Complain? Feature request? Even spamming bots add some more context from time to time - give others a chance, and spell what's on your mind. Anyway, let's assume it was a question, someone else might be interested in answer.
Yes, as documentation says - only File, FileData and string representing a file name are accepted (documentation skips it I think, but it works - you can check in background loading sample I made some time ago, just when threads were re-enabled in 0.7 branch).
Anyway, who needs more? Message passing concurrency is the way to go, look at how well Erlang behaves! Naked shared state, mutexes and semaphores are for bug fans and kids, so they can play with their electric train toy KISS and it is just simpler that way. The fact that you put code in separate file don't tempt you to use something from outside of thread which would make no much sense - and you split the code into multiple files anyway.
Yes, as documentation says - only File, FileData and string representing a file name are accepted (documentation skips it I think, but it works - you can check in background loading sample I made some time ago, just when threads were re-enabled in 0.7 branch).
Anyway, who needs more? Message passing concurrency is the way to go, look at how well Erlang behaves! Naked shared state, mutexes and semaphores are for bug fans and kids, so they can play with their electric train toy KISS and it is just simpler that way. The fact that you put code in separate file don't tempt you to use something from outside of thread which would make no much sense - and you split the code into multiple files anyway.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Love threads?
Giniu, epic post.
Re: Love threads?
Did you just write a short speech about how my thread sucks?giniu wrote:So what? Is this a question? Statement? Complain? Feature request? Even spamming bots add some more context from time to time - give others a chance, and spell what's on your mind. Anyway, let's assume it was a question, someone else might be interested in answer.
Yes, as documentation says - only File, FileData and string representing a file name are accepted (documentation skips it I think, but it works - you can check in background loading sample I made some time ago, just when threads were re-enabled in 0.7 branch).
Anyway, who needs more? Message passing concurrency is the way to go, look at how well Erlang behaves! Naked shared state, mutexes and semaphores are for bug fans and kids, so they can play with their electric train toy KISS and it is just simpler that way. The fact that you put code in separate file don't tempt you to use something from outside of thread which would make no much sense - and you split the code into multiple files anyway.
Hello, I am not dead.
Re: Love threads?
Yes, and you better read it.
Re: Love threads?
I don't usually tl;dr unless the post is about 100 lines long..thelinx wrote:Yes, and you better read it.
Hello, I am not dead.
- Jasoco
- Inner party member
- Posts: 3725
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Love threads?
What exactly is "data" in reference to anyway? What constitutes "data"?
Re: Love threads?
... That's pretty much what I asked, then got a hate post about. You're brave.Jasoco wrote:What exactly is "data" in reference to anyway? What constitutes "data"?
Hello, I am not dead.
- Jasoco
- Inner party member
- Posts: 3725
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Love threads?
Well I know what a file is. But what is data? This is a serious question. Can I send a function into a separate thread? Can threads talk to each other? I'm still confused and intrigued about them.
Also, you didn't really ask a question. You stated a fact. You should have said "What is Data?"
Also, you didn't really ask a question. You stated a fact. You should have said "What is Data?"
- nevon
- Commander of the Circuloids
- Posts: 938
- Joined: Thu Feb 14, 2008 8:25 pm
- Location: Stockholm, Sweden
- Contact:
Re: Love threads?
You can't really send a function. You can, however, send a file containing a function (that is hopefully then also called). You can either do this this easy way by simply making a separate file where you do what you want to do, or you can do this weird shit that bartbes did:Jasoco wrote:What exactly is "data" in reference to anyway? What constitutes "data"?
Code: Select all
local pollservthread = love.thread.newThread("pollserver", love.filesystem.newFileData(([[
require "socket"
sock = socket.udp()
t = love.thread.getThread()
while true do
sip = t:demand("ip")
sport = t:demand("port")
info = "%s"
sock:sendto("%s", sip, sport)
sock:settimeout(2)
local data, ip, port = sock:receivefrom()
if not data then return t:send("name", false) end
if data:sub(1, #info) == info and ip == sip then
local name, version, additional = data:gmatch(info .. ":([^:]*):([^:]*):(.*)")()
local args = {}
for s in additional:gmatch("([^:]*)") do
table.insert(args, s)
end
if name and version then
t:send("name", name)
t:send("version", version)
--t:send("args", args)
end
end
t:send("name", false)
end
]]):format(servbrowser.info, servbrowser.poll), "pollserver.lua"))
Also, don't forget to do thread:start() after creating a thread. That tripped me up quite a bit.
As for threads talking to each other, yes they can. They can use message passing, using the methods: peek, demand, receive, and send.
I can write a small example below. The first file is our main thread, and the other is the thread we're creating.
Code: Select all
local t = love.thread.newThread("workhorse", "filebelow.lua") --Creating our thread and telling it to run the code from the file filebelow.lua
t:start()
function love.update(dt)
local answer = t:receive("answer") -- The receive method tries to get a message called "answer" from the thread, but only if it's ready. Otherwise it just returns nil
if answer then
print("We've solved the mystery of life! It's "..answer)
end
end
Code: Select all
local t = love.thread.getThread() -- Returns the current thread object
local answer = 21*2
t:send("answer", answer) -- Now that we have our answer, we send it back as a message called "answer".
Who is online
Users browsing this forum: Semrush [Bot] and 58 guests