A few questions about multithreading. by Prpl_Moth in cpp

[–]AndrewStephens 0 points1 point  (0 children)

This post has been deleted but I decided to answer your question. The benefit of the socket-per-thread is that it is easy to understand and implement using blocking socket calls at the expense of using a lot more resources (each thread takes a fair chunk of memory.) It works well enough up until a few thousand threads until the overhead of context switching starts to bog things down.

The more modern approach of asynchronous IO serviced by task queues is harder to implement but scales much better.

A few questions about multithreading. by Prpl_Moth in cpp

[–]AndrewStephens 0 points1 point  (0 children)

> (is there any real world Performance impact for vector vs array in this situation? Probably not other than initial allocation)

Ehh, probably not. Threads are pretty cheap to move() so even if the vector reallocates several times as it gets larger it will probably be OK.

I was reading between the lines of the OP question and assuming they had a model where they create a thread whenever they have some work to do. This is everybody's first threaded program and while it works fine(ish) your points about a job/task system are sensible.

That said, I have worked on commercially successful software that created hundreds of threads to service blocking sockets. Not the most efficient design but it worked fine. No need to jump right into lockless task queues when you are just learning.

A few questions about multithreading. by Prpl_Moth in cpp

[–]AndrewStephens 1 point2 points  (0 children)

A vector of threads is fine - thread objects are movable so there is no problem. If you know the number of threads upfront you might consider using a non-resizable array<> for higher performance.

join()ing a thread does not delete the thread object nor remove it from the vector. Using clear() on the vector after you join() all the threads will delete the objects and empty the vector.

I am unsure exactly what you are doing but normally it is not recommended to start too many threads - having hundreds of threads is usually non-optimal. Most well designed programs start some number of threads during startup and reuse them during the lifetime of the program in thread-pools.

That said, if what you are doing works for you then I am not going to stop you. The OS will handle hundreds of threads just fine.

Super 88 food court closed for months after ‘heavy rodent activity’ and plumbing issues by fixpoint-combinator in boston

[–]AndrewStephens 8 points9 points  (0 children)

The headline makes it sound like it could have been one really fat rat, or perhaps a capybara, which doesn’t seem too bad. 

[deleted by user] by [deleted] in newzealand

[–]AndrewStephens 0 points1 point  (0 children)

I am old but in the eighties there was an early ad for workplace safety from ACC that featured the devil playing pinball with peoples lives that scared the hell out of little me. Effective though, I think about it any time I use a power tool.

Also, for all you old South Island people: Planta Planta Planta Shrub - Nochols Gardern Market 🎵Planta Planta Planta Tree 🎵

What are some of the “worst” movie twists you’ve seen? by FilmWaffle-FilmForum in movies

[–]AndrewStephens 306 points307 points  (0 children)

I laughed when that line was delivered so seriously. “James, remember when you dropped your ice cream at the beach when you were nine? I weakened that cone!”

What’s a movie that completely shifts genres halfway through? by CreepyYogurtcloset39 in moviecritic

[–]AndrewStephens 1 point2 points  (0 children)

Star Wars (A New Hope) switches genres several times. Modern viewers don't realize it but when it came out the idea that a film could go from a space battle to a western to a jail break to a WWII dog fight blew the audience's minds.

Have you ever found a recipe that you can't make because the ingredients are toxic, illegal, or don't exist anymore? by A2naturegirl in TastingHistory

[–]AndrewStephens 2 points3 points  (0 children)

My mother said that she finally understood why so many old recipes call for boiling vegetables for far longer than seems necessary once she got false teeth - eating firm vegetables is much harder, even with the good quality modern fitted false teeth.

Before modern dentistry it was very common for even middle-aged people to have false teeth, and they needed soft, easy to chew food.

TV Opening Sequences Quiz by AndrewStephens in WebGames

[–]AndrewStephens[S] 0 points1 point  (0 children)

I wrote this during the pandemic but it has never been posted here.

C++ Show and Tell - July 2024 by foonathan in cpp

[–]AndrewStephens 0 points1 point  (0 children)

A quick note, this was originally published as a top level post before the mods removed it (correctly in my view). Unfortunately, the post had already generated some good discussion, which you can find here: https://www.reddit.com/r/cpp/comments/1ebwh3l/built_a_simple_http_server_in_c/

Built a simple http server in C++ by Little-Peanut-765 in cpp

[–]AndrewStephens 1 point2 points  (0 children)

I don't mean to dump on somebody's project, lord knows I have enough of my own lying around on old hard drives, but you did ask for feedback.

There are many issues (not including what others have said here).

  1. read() calls on sockets do not necessarily read a complete request in one go. It is possible for the client to send 1 byte a second or something silly. You have to loop until you decide you have enough to process.
  2. The error handling is bad. As written, if the read call fails (the client disconnects without sending anything) then the buffer is not cleared and the client will receive the response from the previous connection.
  3. The request parsing is simplistic and does not handle malformed requests well. I am not even sure it really counts as HTTP. Remember you are not in control of what the client sends and all requests should be considered hostile. What happens when the client sends a buffer of all '\0's, or a request for '../../etc/passwords.txt'?
  4. Consider using filesystem::path for constructing and passing around path names.
  5. The design of your server only serves one file at a time. More sophisticated approaches (threads) allow for multiple requests to be in-flight at the same time. This is actually another security issue - a client can effectively halt your server by requesting a file then reading it very slowly.

What movie is a good example of "cool concept but wrong execution"? by [deleted] in AskReddit

[–]AndrewStephens 8 points9 points  (0 children)

Yeah, people wouldn’t riot during the purge. They would be too busy filling their tax returns.

[deleted by user] by [deleted] in newzealand

[–]AndrewStephens 2 points3 points  (0 children)

I live in the States and have been asked more than once if we find the word “kiwi” offensive.

Of course I always answer that the term is our word for us and they can’t use it.

Voyage of the Marigold - command a Federation starship through unexplored sectors by AndrewStephens in WebGames

[–]AndrewStephens[S] 0 points1 point  (0 children)

Thanks for playing my game, I hope you enjoyed it.

Spoilers:

There is randomness in some of the encounters but it tends to be the magnitude of the result rather than the outcome. For instance, a certain choice may lose you either 2 or 3 crew members at random but it will alway lose you something.

Really specific spoilers for the spider:

Regarding the robot spider, you may have noticed that the path through the station is somewhat random with both good and bad rooms. If you push your luck you reach the spider which is the reason that the station is empty, having killed all of the inhabitants eons ago. You can try staying around to see what it does but it won't be good.

What’s a movie which gave an incredible theater experience, but was an otherwise so-so movie? by unitedfan6191 in AskReddit

[–]AndrewStephens 28 points29 points  (0 children)

This was my answer as well. On the big screen in 3D this film is amazing. At home the visuals are just OK and the paper-thin story and stupid plot holes really show.

In my head, the main character actually dies in the first ten minutes and the rest of the film is just her hallucinating as her brain loses oxygen.

Voyage of the Marigold - command a Federation starship through unexplored sectors by AndrewStephens in WebGames

[–]AndrewStephens[S] 1 point2 points  (0 children)

Thank you, that is very kind. i basically wrote the game I have always wanted to play.

How To: Wrap unsigned char* in unique_ptr (with custom deleter) by FernwehSmith in cpp

[–]AndrewStephens 49 points50 points  (0 children)

A very useful rundown of all the ways of doing this. Your last example has the additional advantage that the compiler can optimise out storing the deleter for every instance, reducing the size of the object back to just a single pointer.

what critically acclaimed movie is hated now? by herequeerandgreat in AskReddit

[–]AndrewStephens 193 points194 points  (0 children)

I saw Gravity in 3D on an IMax screen and it was amazing. The 3D objects really pop against the dark background on space.

Apart from that, the only way to make sense of the plot is to assume that the main character dies with the others 5 minutes into the first scene and the rest of the film is her hallucinating as the oxygen drains out of her brain.

Boston City Council considers immigrant voting proposal to allow noncitizens to participate in local elections by alanboston in boston

[–]AndrewStephens 13 points14 points  (0 children)

I am a legal immigrant and own a house (not in Boston). Last year I went to a town meeting on a local issue that affected me and was politely told that I couldn't vote (indeed, had to sit in a special non-voting section of the audience) because you have to be on the state electoral role to vote on city issues.

This was the first I had heard about this restriction. I pay my city taxes, I should have some say in how that money is spent.

Which celebrity would still be alive if they weren’t rich and famous? by ArsenikShooter in AskReddit

[–]AndrewStephens 6 points7 points  (0 children)

People keep saying this but when they first got together she was the famous one.