Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Search - "thread locking"
-
Find super interesting forum thread from 2015 with intelligent discussion about deep technical stuff.
Creating forum account, thinking about contributing to ongoing discussion with code samples, findings, hypotheses, and some open questions.
Browse to last post, is from late 2016, from moderator:
READ FORUM RULES DO NOT POST IN OLD THREADS LOCKING THIS
Me: 😡😤😠 WHO THE FUCK CAME UP WITH THE SHITRULE THAT A DISCUSSION HAS AN EXPIRATION DATE? IF I COULD REACH THROUGH THE SCREEN RIGHT INTO 2016, I'D PUNCH YOU THROUGH THE ROOF OF YOUR MOTHER'S BASEMENT. NO ONE LOVES YOU, YOU USELESS MOTHERFUCKING CUNT OF A MODERATOR.3 -
I'm writing a multi threaded program right now and just pray for the threads not accessing my var at the same time :) but I cannot use a locking algo because my 1st thread needs to access that var up to 1000 times a second. Pray for it to work as it should 🤔😇9
-
@dfox - Idea for weekly rant - worst candidate that showed up to a job interview.
Had a solid resume, claimed to be a Java king, top notch. First question after he sat down: How to create a thread-safe singleton in Java using double-checked locking?
Guy didn't know the answer. - NEXT!14 -
*rewrites rust mpsc*
you did it wroooong
I thought my threads were locking if I had thousands of jobs spawning thousands of more jobs. turns out it's fine. actually if I organize my data locks in the way everyone wants to do them my CPU fans go off but my original way you don't feel jack shit and processes faster
turns out it's because 320k jobs is a bit much for mpsc. because my jobs can spawn more jobs the whole thing just grinds to a halt. and there's sync-mpsc which allows you to have a maximum number of data you send through it, therefore I can just have 245 sent jobs instead of 320k but then this locks all the threads because for a thread to finish it needs to finish sending jobs, but a sync mpsc won't let you send a job if current jobs are over the specified limit. so all the threads get stuck sending jobs. smart. not. what's even the point of that?!
and evidently there's no built-in way to prioritize certain jobs. the AI thinks you should just send jobs in and each thread should have a priority queue. I don't know sounds dumb to me. then you could by random luck have threads with lots of jobs that need to be prioritized to be done and other threads stuck hanging waiting for previous jobs / the other threads. no thanks
so clearly the solution is to rewrite mpsc but allow prioritization when a thread goes in to ask for a job to do
since my jobs are intended to start other jobs, it makes sense to have no actual upper bound limit to the number of jobs in the queue but to favour doing jobs that won't start new jobs to lower the RAM and compute necessary to juggle all this
hope this is the actual problem. cuz the code works for like 200 jobs spawning 500 jobs each, which is 100k jobs total
but it stalls to a halt doing 8300 jobs spawning 500 jobs each (which if I do the math -- in my tests it stalls at 320k jobs and seems the number should be 4,150,00 jobs -- yeah I think this is probably the damned problem)8 -
Python muses me sometimes.
Gunicorn has a preload mode. It enables forking...
So Gunicorn starts, when Gunicorn loaded it forks the workers (Uvicorn / FastAPI in my case).
https://github.com/tiangolo/...
So if we add a function that creates the app... this function will be executed before forking, thus the memory at the state of creating the app will be duplicated.
You can thus spawn 40 workers, they would all have the same ML models.
Or in my case a client who does some things that should only be run by a single thread (with locking).
So the client has a cache, as long as I load the cache during the create_app phase, the cache will be shared between all instances and not created per instance.
It's ... Such a small detail. So simple.
Yet completely fucks my brain.
It's logical, yes. I understand what it does, yes.
But it still makes my brain fart. -
So I've been helping with recruitment at work for a lead developer. Our first stage is pretty standard for all levels and it essentially a technical interview because CVs are useless really. We're a C# house so we have questions on framework internals such as how the dictionary class is implemented, locking and thread synchronization techniques. Then some pen and paper coding excercises, like reverse array.
I'm not a big fan of these and I think they are too constrained to detail implementations and not about concepts.
So I ask what stuff do you do at your company to get an idea of some ones competency?1