Guard your render thread's quit flag somehow, or use atomic_flag or condition_variable. You're modifying and checking it in two diff threads. Also, read up on RAII, it'll save you. the rendy object lifetime destructor happens after SDL_Quit(). This is probably fine with SDL, but be aware that improper ordering of destruction can result in memory leaks and crashing with other libs and even in your own code. Just some tips :)
EDIT: Oh yeah, you don't need "this->" everywhere. You only need it for "this->window = window;" because of the name clash.
EDIT2: SDL_DestroyWindow needs to be called on the same thread that created it. I think this is a platform-specific limitation.
EDIT3: I was suspecting that there was another issue with the SDL state access between threads but I could not remember the rules for it. /u/nope_dot_avi's comment is correct, the unprotected window data is accessed by 2 threads.
Anyone wishing to dive into concurrency should Read this book
This isn't specifically for C (in fact the examples are mostly in Java) but Herlihy and Shavit's The Art of Multiprocessor Programming was a fantastic resource for me for learning parallel algorithm and data structure design. It does a really good job of walking you through a bunch of examples of how to use and write everything from locked data structures to lock-free and wait-free techniques. You'll just have to seperately look up how to use mutexes or atomic instructions (<stdatomic.h>) in C, but the techniques they go over are fairly language agnostic.
I've heard good things about CIS 565 from UPenn. Although they don't have lectures available, the topics they list on the website (https://cis565-fall-2020.github.io/syllabus/) are the topics you'd want to know: scan / reduction algorithms, radix sort, scheduling, etc. Specifically, I think topics 1, 2, 3, 4, 5, and 8 are all important.
Some of the stuff like the hardware features and algorithms specific to graphics are not as important, but it's good to know them to have context on why the GPU hardware is designed the way they are.
If you want a textbook, this book: https://www.amazon.ca/Programming-Massively-Parallel-Processors-Hands/dp/0128119861 looks good just based on the authors and seems to be reccomended by many people.
I think in the beginning though you will probably want to get your hands dirty with CUDA programming first, and try implementing & benchmarking your algorithms (and in the process learn the tooling for profiling and such for the GPU).
I didn't want to add the link because I was conscious of being too spammy. https://www.amazon.com/Rust-Action-Tim-McNamara/dp/1617294551/
If you want to read it straight away, I recommend buying direct from the publisher though (https://www.manning.com/books/rust-in-action?a_aid=rust&a_bid=0367c58f&chan=twitter). That way you can read the ebook before it's officially released to retailers.
Amazon says August 10 but it may be sooner - there's probably a pipeline that's getting kicked into action right now to do that.
I'm pretty sure that that the lock keyword creates a memory barrier. I would have to, otherwise your read could be moved to occur before the lock.
If you really want to learn this stuff, get Duffy's book. It's a hard read due to the amount of information you get per page, but well worth it.
https://www.amazon.com/Concurrent-Programming-Windows-Joe-Duffy/dp/032143482X
If you really want to learn this stuff at a deep level, Concurrent Programming on Windows by Joe Duffy
https://www.amazon.com/Concurrent-Programming-Windows-Joe-Duffy/dp/032143482X/
This predates async/await, but it explains what's really happening inside the operating system.
Have you checked Amazon? The ancient technology known as the textbook is still the best way to learn in 2020, and Amazon has thousands of reviews from real humans on all sorts of different books on this very topic (or any other topic you could want to learn). I doubt you'll get more data points here than you could get by just browsing those reviews.
I used this one in college. I enjoyed it.
Non so su quale basi tu stai fondando questa affermazione. Io ho studiato algoritmi e programmazione multicore (fra le tante cose) e con queste basi, se vuoi, posso dimostrarti matematicamente perché ti sbagli e perché due file sono sempre più veloci di un'unica fila. Specialmente in questo caso. Sinceramente non capisco come tu non riesca ad arrivarci da solo/a in quanto è un'affermazione alquanto triviale da ricavare.
La dimostrazione matematica (e con logica) però richiede tempo e un po' di righe di testo da scrivere e sinceramente non mi va. Se però lo vuoi, lo posso fare. Dimmi tu.
In caso contrario ti consiglio questo libro.
> Bring on the endless Todo list app tutorials comprised of 90% spaghetti.
Free:
https://doc.rust-lang.org/book/
There's also this book:
https://www.amazon.com/Programming-Rust-Fast-Systems-Development/dp/1492052590/
Programming Clojure by Alex Miller
Web Development with Clojure by Dmitri Sotnikov and Scot Brown
I read these two and started making my own project, so far so good
Cool. But I still would like to master atomics. Do you know a good read about this topic. A book maybe? I have a book regarding multithread programming. This one : https://www.amazon.com/C-Concurrency-Action-Practical-Multithreading/dp/1933988770.
I had to rest between some chapters, because overloads my brain pretty fast. 😆
This. Additionally, Stephen Cleary's Concurrency in C# Cookbook, if you're already an established user of C# and want to know what this async/await stuff is all about.
Where I work we’re all seasoned C++ and C hackers. When we adopted Rust I found Programming Rust was the better choice (compared to TRPL) to introduce the language to my colleagues.
Honestly for stuff like that you'd be better off playing around in something like Racket where you can design and implement a language on the fly.
As a language example C++ has mostly been influential as an example of what not to do.
I think this book is a very nice example of how systems programming can be taught using Rust:
https://www.amazon.com/Rust-Action-TS-McNamara/dp/1617294551
> I took a look at the Amazon.com page and it’s showing that it was published on August 10th.
For me, both amazon.com (https://www.amazon.com/dp/1617294551) and the local Amazon show the paperback as only available through third parties despite a publication date of June 29. That probably explains why the preorder hasn’t shipped yet.
That new book that just came out is about rust and system programming. I have no critique of it for you, I just thought it unusual that a beginner book on rust is also about system programming.
Good grief, do I really have to read all 6? I have a full-time job to do! 😊
The Art of Multiprocessor Programming is a really serious work, and to describe it as for "but anyone who wants to learn basics of concurrent programming" is not to do it justice.
​
​
you can probably find free pdfs or something.
never tried it for c# but i used cookbooks for sql and c++
the way they work is they give you a bit of theory and then give good exercises to do.
i find them really good.
other ways would be to follow a lesson plan on c# and then find lots of exercises online about that chapter.
example:
you just studied the chapter on if statements, had 1 exercise and then it continued to next chapter. what you can do is google for if statements exercise for c#, there are load of em. and if you need more just look for exercises in any language and do them in c#. anything beginner level should be possible to do in most languages.
anyway good luck man c# is fun,
What are you trying to do with it? Programming Massively Parallel Processors was useful to me, but without more info, it's hard to make recommendations.
Personally I think it is best to learn c++ by reading books.
In this case the book would be: https://www.amazon.de/C-Concurrency-Action-Anthony-Williams/dp/1933988770
It starts slow with basic multi threading later explains atomics, memory model and other more advanced things with plenty of examples.
I started with this book. I think it's mainly Cuda focused but switching to OpenCL was not that hard.
Hard to say, there's a lot of reasons that can happen and it may not even be a bad thing.
I'd have to look it up to be sure, but I think the default thread pool size in C# is 100 threads.
This is by far the best book on the subject, but it hasn't been updated for TPL.
https://www.amazon.com/Concurrent-Programming-Windows-Joe-Duffy/dp/032143482X
A couple of things here. Multithreading is a subset of Concurrency, which involves managing individual threads doing different work. At one point in time, this was the only way to achieve concurrency in .Net, but currently there are several options, all of which are much better.
Multithreading is also VERY hard to get right, so I highly doubt that a company would want someone to "pony up" on it over just a month. Multithreading is something that even people who have been doing it for years have trouble getting right.
I can highly recommend Stephen Cleary's book Concurrency in C# Cookbook, which goes into many different ways to achieve concurrency without diving into threads. As he says in the book, the moment you start writing something using threads, its already legacy code. Async/Await, Task Parallel Library, PLINQ, Reactive Extensions, Concurrent collections, Locks. Those are all things you should be getting familiar with. The book itself is definitely in the cookbook/recipe format, but also gives good explanation as to what's going on in the code and why rather than just having the code.
As far as ideas for an app, one that's been in my mind for a while is an elevator management system. Its a problem that is simple enough for a small app that people will be able to understand really easily. Its got a number of different components; multiple elevators, multiple requests. It has a lot of state and decisions built into it. I also think you could play around with the configurability of it as well; test it under different loads, determine what happens with n-2 or n+2 elevators, how the speed of the elevators effect service, etc.
Other book:
Other lib:
Other tools (free for open source):
Continuous build + test
static analysis
Introduction to Multiprocessor Programming, based on this book.
It was an amazing introduction to concurrent data structures, I've enjoyed every minute.
(Having one of the book's authors teach it helped, too)
This was quite nice during my undergrad. It does a really nice job of exposing concepts while using Java as the tool.
The book on the topic is "Concurrent Programming on Windows" by Joe Duffy. It covers all of the topics you listed, both at a high level and with as much depth as you can handle.
Would you recommend Effective Modern C++? I've been writing in C++ for 2-3 years now, and I've already read "Effective C++" and "More Effective C++" cover-to-cover, so I wouldn't consider myself a newbie... mainly, I'm just looking to learn multithreading, and I was considering a book such as this one.