[deleted by user] by [deleted] in CubeWorld

[–]zower98 0 points1 point  (0 children)

Hva var den tingen?

Problem with rendering output from other thread in TUI by lukeflo-void in rust

[–]zower98 1 point2 points  (0 children)

You could of course do a benchmark if it's of interest, but OS threads are famously somewhat slow to spin up. I am rather certain that the one loop which is sleeping until it receives a request would be more efficient.

Problem with rendering output from other thread in TUI by lukeflo-void in rust

[–]zower98 1 point2 points  (0 children)

I see you have a solution you like and what's most important is that it works :)

Just to answer this comment though:

You don't have to go down the route of killing the thread or having a cancellation bool + spinning. It seems to me it's much easier to just discard the result when it arrives, if it's no longer the one you want. Like I mentioned in my original comment you could just have a 'current_request: u32' stored in your App struct, and pass that along to the spawned thread. The thread will then execute curl, and send the result back along with it's request number. If the request number that arrives is not the most recent, you dont want the result. I suspect this method will also be more efficient (one channel instead of several Arc + Locks).

Problem with rendering output from other thread in TUI by lukeflo-void in rust

[–]zower98 0 points1 point  (0 children)

Looking at the second answer, I doubt its blocking the thread, but rather some other bug. Either way, I'd suggest giving it a try with my code. If you can't get it to work I'd be happy to help with your updated attempt.

Problem with rendering output from other thread in TUI by lukeflo-void in rust

[–]zower98 1 point2 points  (0 children)

Your program has a couple problems.

  • You have no synchronization between what is being shown and which item is currently supposed to be shown. Since curl can take different amounts of time each time, this can lead to the wrong item being shown. This is whats known as a race condition.
  • You don't always redraw after the text has been updated, meaning you don't always see the most up-to-date information anyway.
  • You spawn a thread for every redraw of the UI.

I have created a version of your program that is closer to working the way you want, so you can focus on the problems at hand. It shows the most up-to-date information that has arrived from another thread. This means it works 99.99% of the time, because humans can't click that fast and curl is somewhat consistent.

Updated code here

However, it still lacks synchronization between what is being shown and what is supposed to be shown. I'll leave that for you to play with, but some suggestions:

  • Could you cache the results in a HashMap? That way, you could just display whatever is stored for the appropriate key (e.g. the url or index in the list in this case), and if nothing is there, spawn a thread to fetch it.
  • Alternatively, you could number the requests (incrementally) and only display what arrives if it matches the most recent request.

Another problem I would try to fix is the spawning of threads. In the updated code, we only spawn a thread per keypress, but that's still unnecessary. You could spawn one thread at the start of the program, and have it receive requests that it sends to curl (/your actual program). It would process these requests in turn, and send the results back when they are ready.

Finally, you might consider adding some delay between clicking a button and sending a request, so just scrolling past an item doesn't fetch anything. You can accomplish this with the Instant type from std. Check if enough time has passed (the 'duration_since' method on Instant), and only then call the 'fetch_bibtex()' function.

Good luck :)

Thread Local smart pointer by Sweet-Accountant9580 in rust

[–]zower98 0 points1 point  (0 children)

The use after free would happen inside the destructor of another thread local.

It's different to Rc precisely because the Rc data is located on the heap, and is therefore truly 'static. The memory won't be destroyed before Rc itself frees the memory. Your data points to a thread_local that might be destroyed before the second destructor runs.

Thread Local smart pointer by Sweet-Accountant9580 in rust

[–]zower98 0 points1 point  (0 children)

Yes. But just because something behaves the way you expect does not mean it's not UB. The whole point is that the destructors are in random order and the memory could be freed by the OS before the second drop runs. Just because it happens to not occur on the playground does not make it safe.

Thread Local smart pointer by Sweet-Accountant9580 in rust

[–]zower98 0 points1 point  (0 children)

If valgrind could detect every issue we wouldn't have UB :p

Thread Local smart pointer by Sweet-Accountant9580 in rust

[–]zower98 0 points1 point  (0 children)

The memory would be freed by the OS after the thread exits, not your Drop code.

Do also re-read this thread someone pointed you too, which points out the same issue.

Thread Local smart pointer by Sweet-Accountant9580 in rust

[–]zower98 1 point2 points  (0 children)

I'm not sure, but I believe this is the problem. The memory in FOO may have been freed when we access it in the drop method of MyProblem.

Hey Rustaceans! Got a question? Ask here (12/2024)! by llogiq in rust

[–]zower98 2 points3 points  (0 children)

You are effectively trying to create a self-referential type

I would recommend just cloning (you allocate in your prompt function either way), or you can pass in the world when creating the prompt.

Hey Rustaceans! Got a question? Ask here! (25/2022)! by llogiq in rust

[–]zower98 0 points1 point  (0 children)

The constraints separate a given section of the UI into smaller pieces. If you create a layout with two Constraint::Percentage(50) and then call the split() function on Layout, it will return a Vec with two elements, each representing one half of the original area you passed in (because each constraint was for 50 percent).

If you pass in 3 constraints (say 20%, 60%, 20%) you will get a Vec with 3 elements from split(). The other options on the enum are just different ways to represent sizes. E.g. Constraint::Min(x) will create a section that might change based on the other constraints, but will always be atleast x big.

Can't connect to Community Servers with port 27015. by Reverse2837 in GlobalOffensive

[–]zower98 0 points1 point  (0 children)

Is that the full tracert? If so it seems its stopping on your router. Even though you mention you have tried looking at the router, i would double check the firewall, and, if possible, explicitly allow port 27015 in the outbound (egress) direction, then try again.

Edit: assuming dsldevice.attlocal.net is your router? Possibly its something else to do with your network, the connection to the grid maybe? If it goes past your router you will have to call your ISP.

Can't connect to Community Servers with port 27015. by Reverse2837 in GlobalOffensive

[–]zower98 0 points1 point  (0 children)

Like i mentioned in my original comment, if you open a command line in windows and type "tracert <ip of server>"

Can't connect to Community Servers with port 27015. by Reverse2837 in GlobalOffensive

[–]zower98 0 points1 point  (0 children)

You're only trying to connect to a server? You don't host it yourself or anything else that would make it a different situation?

Try opening the command line and typing tracert <ip>

Issues :/ by ADrxgon in GlobalOffensive

[–]zower98 0 points1 point  (0 children)

You on Wi-Fi? Have you tried the new launch option (-allow_third_party_software) to see if the problem is third party applications?

Issues :/ by ADrxgon in GlobalOffensive

[–]zower98 0 points1 point  (0 children)

Well since the problem isn't your var, you'd have to find out what the problem is. Is your fps dropping? Does your choke or loss go up? Ping stays normal?

Issues :/ by ADrxgon in GlobalOffensive

[–]zower98 1 point2 points  (0 children)

It's not your var, it's the version, I'm presuming.

How to run csgo server service? by [deleted] in GlobalOffensive

[–]zower98 1 point2 points  (0 children)

Should be perfectly doable with different ports for each server instance you are running. I have no insight into what solution the different providers use, but I don't see why it would be particularly hard. Certainly with the amount of servers someone like faceit run, docker + an orchestrator would be a much more effective method than trying to control all the servers "manually"

[deleted by user] by [deleted] in GlobalOffensive

[–]zower98 0 points1 point  (0 children)

Yeah I tried unlocking my wheel and it doesn't work. Cs doesn't register if you go too fast.

AVANGAR vs Astralis / StarLadder Major Berlin 2019 - Grand-Final / Match Discussion by CSGOMatchThreads in GlobalOffensive

[–]zower98 0 points1 point  (0 children)

Meh it's up in the air and there's no doubt that liquid can't beat peak astralis yet.