Threads are the devil. Never -lpthreads if you know what's good for you. Threads were introduced to our code by Russian agents trying to subvert the productivity of American programmers in the cold war. Spawning a thread is the single worst thing your program can do. Say no to threads. Friends don't let friends use threads. Don't fucking use threads!

This isn't a joke, it's a warning. Threads will fuck your wife.

You don't need to do several things at once. You need an event loop and poll.

But if you really, really think you need to do several things at once

You don't.

But if you won't listen to me, use fork and pipe instead of threads.

Follow

Run this command:

grep '^processor' /proc/cpuinfo | wc -l

That is the number of things your computer is capable of doing at once. Now run this command:

ps aux | wc -l

This is the number of things your computer is trying to do at once right now.

Threads are not magic, they can't make your computer do more things at once than it's capable of. Who would you rather be in charge of scheduling: preemption, which will take control away at random times, including in the middle of writes; or your code? Say no to threads. Design your code like a fucking adult.

Fuck the idea that null is the most expensive programming mistake ever. Fucking THREADS are. Fuck threads.

@sir Use message queues to communicate between hardware threads. Implemented however you need: lightweight POSIX threads, properly isolated processes, keeping the queues in shared memory, or processes running on different machines. The implementation doesn't really matter, as long as you aren't reinventing the wheel^Wlow-level synchronization primitives.

And also, consider liburcu for data-structures, libuv for work queues, and libczmq for the framing.

@sir NULL-pointer as such is not the problem — it's just `option` wrapper. Letting the programmer access the value without pattern-matching first — that's one of the things wrong with C.

@amiloradovsky I am familiar with the null "problem". Threads are way, way, way, way worse.

@sir There is no way to escape them in general — shared-memory parallelism needs to be utilized somehow. And the processes are somewhat heavier.

OTOH, threads are PITA. — One should try to avoid them at first.

@sir @amiloradovsky So you're saying... DOS batch files were multitasking done right?

@sir now run ps aux without piping it to wc -l

see all those processes with S? those processes aren't running right now, but could potentially run later

see any processes with Z? those processes don't even exist. they're just placeholders to make sure the process IDs don't get reused until the parent process acknowledges that they finished

see any processes with X? something is wrong with your computer

@ben s/wrong with your computer/wrong with Linux/

s/wrong with Linux/wrong with Unix/

s/wrong with Unix/wrong with your computer/

@sir if you can see a process in X state, that means your computer is showing you a process that's already exited and been cleaned up

@sir Type this command to get the number of threads that you as a programer can easily manage:

echo 1

@sir 4 / 271 😞 ... I guess your ratio is much better with your setup using alpine (no systemd) and no DE?

@sir Yes, let's switch back to cooperative multitasking

@sir ok since you won't pay me to explain why you're a transphobic bigot, at least tell me why context switching, especially a method that keeps one thing from taking down the whole system, isn't worth the completely reasonable overhead cost :blobcatsip:

@anna this post wasn't arguing against context switching in general, and especially not arguing against context switching as a means for the kernel to keep your userspace programs in check, but rather against the idea that preemptive multitasking somehow can magically make your program "do two things at once"

@anna and since your program is just going to do one thing at a time anyway, planning the scheduling of tasks yourself is a much more reliable solution than letting the kernel switch between your tasks effectively at random

@anna for additional access to my expertise on preemptive multitasking please subscribe to my patreon

@sir your answer is dumb and you still havent paid off your debt, especially since we TRIED cooperative multitasking and it was buggy and crashy as hell. "just write good code :4Head: " isnt an answer to that, because nobody is going to do that shit, and especially in the year of our dark lady two thousand twenty, some bug in the newest bullshit web framework of the week that everyone is using taking down people's wholeass computers on a twice a week basis sounds like a nightmare

@anna can't wait for the next random post in my history you dig up to write a nonsensical rant about

@anna you still had to come back to my profile two hours later to find it 😉

@sir oh wow i had to get up from the computer for a while and also do some work wow cool dude you sure pwned me 🙄

if you must know kaniini said you are "not a bad person" so i was going to see if you had anything worthwhile to say about anything and just. pinned. right there.

@anna I stopped taking you seriously a while ago, now I'm just trying to get a rise out of you every time you post

@anna @sir

> we can't expect engineers to know what they're doing

:thinking_cirno: if you don't know what you're doing git gud or get a different job pls. you're making the rest of us look bad.

@xj9 @sir why is this about me? i don't write all the code out there, and i sure do not have high expectations for checks notes almost all of it

@anna @sir

i'm talking to the engineers who don't know what they're doing. which may or may not include you, i wouldn't know since i haven't read any code that you're responsible for.
@anna @sir nvm just read through that whole argument, and uh, calling people who don't take a hardline stance on things and instead occasionally make posts that they no longer agree with because they were genuinely misinformed on the subject "bigots" is a dumb thing to do and is just going to polarize them further towards the other side

@birb @sir we dont got time to explain basic-ass "how to not be a transphobic piece of shit 101" to everyone that comes along, maybe instead of blaming people who gave him that free education, blame him for wanting to have an argument like a little pissant instead of accepting that maybe the multiple trans people who have laid out in detail why this shit sucks ass know more about this than him

@sir is this a take on shared memory multitasking or not?

like, goroutines

@steph yes, this is a take on shared memory mulititasking

@sir manual event loops suck as a programming model

i think erlang got it ~right in this area but having shared memory as a fallback isn't a terrible thing

@steph I think event loops or coroutines are the way to go

@sir well i agree on coroutines, but i guess you'd have non-shared memory between coroutines and only message passing

@steph coroutines can share memory without any ill consequences, or at least 100x more so than preemptive multitasking. Message passing and memory isolation are only necessary for preemptive multitasking or multiprocessing

@sir so you don't like shared memory parallelism but you do like shared memory concurrency
Sign in to participate in the conversation
Mastodon

The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!