News for hackers. Stuff that matters.
Re:Show HN: uThreads – Concurrent User Threads in C and C++ by krat0sprakhar on Monday November 07, 2016 @01:51PM (#12893720)
This looks super interesting! I've been working on a Raytracer in C++ and I was recently looking into a threading library which I can use to parallelize the rendering. Surely going to try this out in the coming weekend.

Unsolicited suggestion - while benchmarks and the motivation are important for a threading library, a code snippet of a simple parallel program on the home page would be something that I'd love to see.

Great job, though!

Re:Show HN: uThreads – Concurrent User Threads in C and C++ by rsp1984 on Monday November 07, 2016 @04:21PM (#12895241)
It sounds to me like what you'd need for ray tracing is a fork/join threading model with a master and several worker threads. OpenMP provides exactly that and is a widely supported standard. I'm curious: Why would you use anything else?
Re:Show HN: uThreads – Concurrent User Threads in C and C++ by CyberDildonics on Monday November 07, 2016 @05:07PM (#12895662)
Fork and join is one type of concurrency technique, but to think you wouldn't need anything else is silly. Non shared memory concurrency and pipelined concurrency are two more techniques that can be used.
Re:Show HN: uThreads – Concurrent User Threads in C and C++ by rsp1984 on Monday November 07, 2016 @05:49PM (#12895967)
I was stating this in the context of ray tracing. Why not just use OpenMP and be done with it?
Re:Show HN: uThreads – Concurrent User Threads in C and C++ by CyberDildonics on Wednesday November 09, 2016 @03:41PM (#12914419)
I answered that question. OpenMP fork-join concurrency can be useful for certain parts of a ray tracer depending on the overall architecture. It is far from the only way and can have many draw backs when it comes to overhead, synchronization and memory locality.
Re:Show HN: uThreads – Concurrent User Threads in C and C++ by zokier on Monday November 07, 2016 @03:40PM (#12894837)
Isn't raytracing almost completely CPU-bound? Seems like a odd use-case for green threads, which afaik are more commonly used for IO-bound tasks.
Re:Show HN: uThreads – Concurrent User Threads in C and C++ by krat0sprakhar on Monday November 07, 2016 @03:55PM (#12894985)
You're absolutely right - raytracing is CPU-bound. However, one can still parallelize per-pixel rendering computations on separate cores. Here's an example of a path-tracer written in Go, spawning a new go-routine for this very use-case https://github.com/fogleman/pt/blob/master/pt/renderer.go#L6...
Re:Show HN: uThreads – Concurrent User Threads in C and C++ by comex on Monday November 07, 2016 @04:39PM (#12895413)
If you just want to start num-CPUs threads like that code does, there is no advantage of green threads over regular ones, std::thread in C++. If you want to start a thread per pixel or something, green threads could work, but it's probably more efficient to keep track of state manually.
Re:Show HN: uThreads – Concurrent User Threads in C and C++ by CyberDildonics on Monday November 07, 2016 @05:09PM (#12895671)
Yes, using green threads for ray tracing is basically nonsense, since keeping actual threads busy is no overly difficult.
Re:Show HN: uThreads – Concurrent User Threads in C and C++ by tomjakubowski on Monday November 07, 2016 @05:46PM (#12895941)
It's not nonsense if, to render each pixel, you issue an HTTP request containing the scene/eye data and requested pixel coordinate, and wait for a response to come back from your magic render farm that lives in "the cloud". Now your "ray tracer" is totally I/O bound! :-)
Re:Show HN: uThreads – Concurrent User Threads in C and C++ by edvinbesic on Monday November 07, 2016 @08:07PM (#12896775)
Not sure if /s, but, to rasterize a 1920x1080 image you would make 2073600 HTTP requests? Sound reasonable.
Re:Show HN: uThreads – Concurrent User Threads in C and C++ by Someone on Tuesday November 08, 2016 @03:06AM (#12898487)
Double that if you want to PUT the pixels on a screen.
Re:Show HN: uThreads – Concurrent User Threads in C and C++ by saman_b on Monday November 07, 2016 @01:54PM (#12893750)
Thanks! good point; now that I look at the page, there is not a single sample code in there. I'll update it soon.
Re:Show HN: uThreads – Concurrent User Threads in C and C++ by krat0sprakhar on Monday November 07, 2016 @01:58PM (#12893796)
Awesome! As an example, Rayon[0] does a very good job (IMHO) at this.

[0] - https://github.com/nikomatsakis/rayon

Re:Show HN: uThreads – Concurrent User Threads in C and C++ by saman_b on Monday November 07, 2016 @02:34PM (#12894193)
Thanks, oh all those fancy functions. I need to improve the interface a bit, as for now everything is only based on using uThreads as the unit of concurrency. e.g., this is a recursive Fibonacci: https://github.com/samanbarghi/uThreads/blob/master/test/Fib... and a fork-and-join Fibonacci: https://github.com/samanbarghi/uThreads/blob/master/test/Fib...

There is no fork-and-join in uThreads yet, and I created it using create and join. The interface will improve in the future :)