Remix.run Logo
grg0 5 hours ago

Why are you using pthread instead of std::thread?

pg83 5 hours ago | parent | next [-]

I guess I just didn't notice. In any case, it wouldn't have been std::thread, but https://github.com/pg83/std/blob/master/std/thr/thread.h from my bike lib!

grg0 5 hours ago | parent [-]

What do you mean you didn't notice? I saw another comment about Claude below, are you not even reviewing the output?

I just browsed the project for two minutes and it's one of the first things I noticed. std::thread is more portable (Windows, if anyone cares) and allows you to pass in a lambda, which keeps the code local and also has the compiler generate the closure for you instead of having to pass function pointers and void* captures around. I don't see any advantage to using pthread directly.

pg83 5 hours ago | parent [-]

> What do you mean you didn't notice? I saw another comment about Claude below, are you not even reviewing the output?

Of course I looked at the LLM output, but people, uh, make mistakes and can miss something.

> std::thread is more portable (Windows, if anyone cares) and allows you to pass in a lambda, which keeps the code local and also has the compiler generate the closure for you instead of having to pass function pointers and void* captures around. I don't see any advantage to using pthread directly.

These are obvious things, and the objections to them are equally obvious. For example, std::thread is an additional level of abstraction over pthreads, which, in essence (not in form), gives me nothing. And I don't care about Windows, really.

quotemstr 5 hours ago | parent | prev [-]

One advantage to using pthread is the ability to call pthread_setname_np to name threads and thereby make debugging easier. Granted, you can call it with std::thread by using std::thread::native_handle() to get the pthread handle, but you're still using a non-std::thread API.

grg0 5 hours ago | parent [-]

I see, I wasn't aware of that one. Typically I'd assign an ID, but yeah, names make things easier.