Guild icon
DDraceNetwork
Development / developer
Development discussion. Logged to https://ddnet.tw/irclogs/ Connected with DDNet's IRC channel, Matrix room and GitHub repositories — IRC: #ddnet on Quakenet | Matrix: #ddnet-developer:matrix.org GitHub: https://github.com/ddnet
Between 2019-12-03 00:00:00Z and 2019-12-04 00:00:00Z
Avatar
0498df2 Update localizations (Thanks to Cellegen for report) - def- d597322 Merge #1978 - bors[bot]
Avatar
c1a7961 Write out sql server prefix to failed_sql.sql - def- d8cd6aa Merge #1976 - bors[bot]
Avatar
37ef242 Clean up color handling a bit - def- e02cd32 Merge #1979 - bors[bot]
Avatar
ChillerDragon 2019-12-03 13:52:11Z
Is it saver to call static functions from threads than class methods?
Avatar
[quakenet] Learath2 BOT 2019-12-03 13:53:30Z
No difference, however you can't pass a non-static method as a pointer, so the first is usually more convenient.
Avatar
ChillerDragon 2019-12-03 13:54:06Z
oh ok thats nice
13:54
but if i singiggle snuggly my sketchy pointer to a object in my thread i can happily call methods there even if they get executed in other threads as well?
13:55
only problem is object variables i guess
Avatar
[quakenet] Learath2 BOT 2019-12-03 14:19:41Z
You can't even take a pointer to a member function iirc
14:20
and it wouldn't even make much sense, you can't call a member function without an object. It's signature actually includes the object as a parameter
Avatar
ChillerDragon 2019-12-03 14:23:13Z
yy i have a pointer to the obj
Avatar
[quakenet] Learath2 BOT 2019-12-03 14:23:42Z
If you just pass a pointer to the object that's also fine. But threads are pretty dangerous
14:23
You might want a lock
Avatar
ChillerDragon 2019-12-03 14:24:28Z
i dont know exactly what a lock is but i have a var that is shared by both threads and tracks state of thread
Avatar
[quakenet] Learath2 BOT 2019-12-03 14:27:46Z
When you modify a variable another thread could be reading that variable and that causes issues. To fix it you can have a lock, that makes sure only one thread is using the variable at a time
Avatar
ChillerDragon 2019-12-03 14:28:47Z
hmm sounds good
14:28
but too lazy rn to understand how to use it xd
14:29
i dont see how my threads could mess something up
14:29
ikr famous last words
Avatar
[quakenet] Learath2 BOT 2019-12-03 14:29:29Z
Or you can make reads and writes atomic, which fixes a lot of issues but there still might be other timing issues, e.g. memory ordering :/
Avatar
ChillerDragon 2019-12-03 14:30:25Z
my main thread sets the state var to running then spawns a thread if not running already and the thread then sets state to done and the main thread checks if its done in the gameloop
14:30
sounds save to me
14:30
so i spawn max one thread at a time
14:30
*additional
Avatar
“Some people, when confronted with a problem, think ‘I know, I’ll use multithreading’. Nothhw tpe yawrve o oblems.” (Eiríkr Åsheim, 2012)
Avatar
ChillerDragon 2019-12-03 14:31:16Z
xd
14:31
im sure it will be fine 🙂
Avatar
Well the writes and reads are not atomic, so the thread can set the value halfway, then the other thread can read a trap representation, which invokes undefined behaviour
Avatar
ChillerDragon 2019-12-03 14:33:13Z
what reads and write you mean? to file?
Avatar
Reading and writing to the variable in the memory
Avatar
ChillerDragon 2019-12-03 14:33:29Z
oh wait ye i read and write to file at same time ur right its messed up xd
14:33
but not to variables
14:33
as far as i know
Avatar
Well even the variable that holds the state isn't safe, CPUs don't write in one cycle
Avatar
ChillerDragon 2019-12-03 14:34:02Z
uh
14:34
yikes
14:34
ok my thread is messed up in all possible ways then
14:34
teach me locks senpai
Avatar
Is this teeworlds code?
Avatar
ChillerDragon 2019-12-03 14:34:25Z
yy
Avatar
Why don't you just use engine jobs?
Avatar
ChillerDragon 2019-12-03 14:34:36Z
looked scary to me
Avatar
@heinrich5991 made them pretty safe iirc
Avatar
ChillerDragon 2019-12-03 14:34:54Z
i can imagine
14:35
but harder to understand than the crap i built
Avatar
Well actually idk if 0.7 got heinrichs engine jobs
Avatar
ChillerDragon 2019-12-03 14:35:08Z
mimimi
Avatar
What are you making?
Avatar
ChillerDragon 2019-12-03 14:35:20Z
ranking
14:35
reading files calculating rank
14:36
but i just realized during the rank calculation other ranks could be saved and then there is read and write to file at the same time which is not too good
Avatar
This is why people use sql for this kind of stuff 😄
Avatar
ChillerDragon 2019-12-03 14:36:28Z
:/
14:36
onbgy doesnt
14:36
he is my big idol
Avatar
Well I guess you can just do it naively and hope things don't go wrong?
Avatar
ChillerDragon 2019-12-03 14:37:01Z
uff
14:37
sounds like a chiller approach
14:37
but works better when i can still hope my code is not broken
Avatar
You can have a lock for the object you are passing around just to be safe
Avatar
ChillerDragon 2019-12-03 14:38:21Z
do you have a quick lock snipped
14:38
LOCK l = lock_create() i g
Avatar
LOCK m_Lock;
14:38
m_Lock = lock_create(); yep
14:39
Then in the gameloop you only ever lock_trylock(obj.m_Lock);
14:39
If trylock returns true that means you have the lock, and you can touch the contents of obj safely
14:39
else just go on, it'll probably free up in a couple gameloops
14:40
in the other thread whenever you need to touch the contents of the obj, you first do lock_wait
14:40
which will wait until the lock is available to you
14:40
after you get the lock you can do things with the object
14:40
after you are done touching the object always lock_unlock
14:41
that's all, locks are simple synchronisation primitives
Avatar
ChillerDragon 2019-12-03 14:41:38Z
does it matter where the lock is?
14:41
like on what object or somethin?
Avatar
Make it a member of the object
Avatar
ChillerDragon 2019-12-03 14:41:58Z
or is it just a state i have to use consitently for what ever i want?
Avatar
The object you are "locking" that is
Avatar
ChillerDragon 2019-12-03 14:42:11Z
so my poiter to GameServer?
Avatar
Wait you are locking the gameserver? 😄
Avatar
ChillerDragon 2019-12-03 14:42:24Z
and then make the lock member of CGameContext
Avatar
No no no no, that's very illegal
Avatar
ChillerDragon 2019-12-03 14:42:30Z
:/
14:42
xd
14:42
well my thread state var is a member of CGameContext
14:42
thought thats fine
Avatar
I see what you are doing, there is no safe way to do it
14:43
Atleast not without major work on the code that I stopped doing a couple weeks ago because nomotivation
14:43
The proper solution to this is to have a "job queue" for the gameserver so that we can safely signal the gameserver to do things from within a thread
14:44
@ChillerDragon you can for now, just make your state variable atomic
Avatar
ChillerDragon 2019-12-03 14:44:38Z
this sounds like work do you think its even worth the effort if i get problems with two threads reading and writing to files at the same time anyways?
14:45
sounds like i need a job queue for file io
Avatar
@ChillerDragon reading and writing to the same file without synchronisation is a lot of trouble
Avatar
ChillerDragon 2019-12-03 14:45:21Z
y
Avatar
The usual idea is to create a lockfile
Avatar
ChillerDragon 2019-12-03 14:45:38Z
whats that
14:45
a actual file?
Avatar
If you are using the file test.txt for example
14:45
You create the file test.txt.lck
Avatar
ChillerDragon 2019-12-03 14:45:57Z
ah i see
Avatar
And whenever you want to use test.txt, you first check whether a .lck file exists
Avatar
ChillerDragon 2019-12-03 14:46:14Z
yy
Avatar
if it does you have to wait
Avatar
ChillerDragon 2019-12-03 14:46:28Z
implementing wait alone sounds like a struggle
Avatar
It's quite simple
Avatar
ChillerDragon 2019-12-03 14:46:53Z
ye?
Avatar
In your thread loop you check whether the file exists
Avatar
ChillerDragon 2019-12-03 14:47:00Z
sounds like many things can go wrong
Avatar
if it doesn't just sleep a while
Avatar
ChillerDragon 2019-12-03 14:47:07Z
well so i need a thread loop
14:47
for every file io
Avatar
Well it's probably more performant then spawning a new thread the next gameloop if the file is not available
Avatar
ChillerDragon 2019-12-03 14:49:56Z
or i dont wait
14:50
if i read a file from two threads at the same time is that save?
Avatar
You could maybe get fancy with creating a hashtable of semaphores that get triggered when a modifying thread quits and is removed if there are 0 threads for a file left
14:50
@ChillerDragon no
Avatar
ChillerDragon 2019-12-03 14:50:43Z
so in main thread where i have to write and do important stuff like saving i create lock files and from the rank thread i just abort if lock file exist and done
14:50
so /rank doesnt work when a file is currently updated
14:51
np
14:51
i rly dont wanna get fancy
Avatar
Well the reading is probably safe, but there is no guarantee that the things read will be the same
Avatar
ChillerDragon 2019-12-03 14:51:39Z
wot?
14:52
what do you mean by the same? Do you mean somehow altered values by magic or simply old values not updated yet?
Avatar
This is all a bit complicated, when two threads read the same file, it is usually safe
Avatar
ChillerDragon 2019-12-03 14:53:57Z
ok sounds good to me
Avatar
but if the file is opened non exclusively and a write happens inbetween the reads, the second read might read a half modified file, or a fully modified file, or a non modified file, it all depends on how the write is scheduled by the OS
14:54
@ChillerDragon yeah what you proposed works, as long as /rank doesn't work if there is a lockfile it's fine
Avatar
ChillerDragon 2019-12-03 14:54:49Z
yy
14:54
sounds like fine ux to me
Avatar
And as long as you never have a thread write to the rankfile without creating the lockfile
Avatar
ChillerDragon 2019-12-03 14:55:08Z
get a error in the rare case while typing /rank and just redo it
14:55
ok any good conventions for lock files? Anything in tw code already to create and check for lockfiles?
14:56
is ther something in place for settings?
14:56
or should i just use first lockfile answer from stackoverflow
Avatar
Doesn't really matter
14:58
We don't have lockfiles in tw code
Avatar
ChillerDragon 2019-12-03 14:58:24Z
so the io_write etc code is not very safe?
14:58
when closing two tw clients at the same time my settings might get messed up?
Avatar
Yes if you are very unlucky and not on windows
Avatar
ChillerDragon 2019-12-03 14:58:58Z
y just saw that
14:59
windows seems to be save
Avatar
windows enforces exclusivity
Avatar
ChillerDragon 2019-12-03 14:59:14Z
sounds like a issue to me tbg
14:59
tbh*
Avatar
on POSIX you can get the same behaviour with flock iirc
Avatar
ChillerDragon 2019-12-03 14:59:33Z
mby we should implement that
14:59
loosing settings can be tragic
15:00
cant belive that windows is superior in this case
15:01
ima buy a windows vps now 😄
Avatar
"superior"
Avatar
ChillerDragon 2019-12-03 15:01:24Z
wait but what does windows do then?
15:01
just fail?
Avatar
It also commonly breaks software
15:02
Yeah fopen fails
Avatar
ChillerDragon 2019-12-03 21:01:01Z
no way that made it to teh start page xd
Avatar
ChillerDragon 2019-12-03 22:46:39Z
Again @heinrich5991
22:46
Is this becoming a memes
22:47
Or do I have trouble distinguishing talks by this guy
Avatar
again?
22:47
the latter
Avatar
ChillerDragon 2019-12-03 22:47:12Z
Idk
22:47
K
Avatar
Cellegen | HU 2019-12-03 23:14:00Z
@ChillerDragon is there any program that ports 0.6 map into 0.7 without breaking too much shit?
23:14
also 0.7 map editor... fucking fix it
23:14
or i wont go to 0.7 ever
Avatar
amazing vid btw
Avatar
ChillerDragon 2019-12-03 23:53:45Z
@Cellegen | HU i did not find any tool for porting maps that really convinced me. And my attempt to implement ddrace layers to 0.7 client was also kinda experimental so idk when that is gonna happen.
Avatar
Cellegen | HU 2019-12-03 23:54:25Z
i have a hell of a trouble with scaling images just so that the editor can properly render it
23:54
cuz it doesnt have autoscale
Avatar
ChillerDragon 2019-12-03 23:54:33Z
?
Avatar
Cellegen | HU 2019-12-03 23:54:47Z
my picture of an unhook tileset is 600x600 px
23:55
and somehow its over 600kb
23:55
like wtf???
23:58
oh alright, ddnet graphics tools
Exported 179 message(s)