|
GameCube posted:hey you terrible freaking programmers. if i've got a semaphore and one thread has been waiting on it for five minutes and then another thread comes along and waits on it the new thread might get the semaphore before the old one does. that sucks. how do i make it not do that. thanks in advance for answering my question about programming use a queue
|
# ? Jul 6, 2016 16:33 |
|
|
# ? May 23, 2024 05:34 |
|
GameCube posted:hey you terrible freaking programmers. if i've got a semaphore and one thread has been waiting on it for five minutes and then another thread comes along and waits on it the new thread might get the semaphore before the old one does. that sucks. how do i make it not do that. thanks in advance for answering my question about programming the reason it does that is because making it strictly ordered makes it way slower (and is in most cases unnecessary). if you really do want strict queueing behaviour, use a higher-level synchronization mechanism that offers that.
|
# ? Jul 6, 2016 16:34 |
|
GameCube posted:hey you terrible freaking programmers. if i've got a semaphore and one thread has been waiting on it for five minutes and then another thread comes along and waits on it the new thread might get the semaphore before the old one does. that sucks. how do i make it not do that. thanks in advance for answering my question about programming you need to implement a queue for the semaphore. there may be a function for this already or you may have to implement it yourself, you didn't say what environment you're in. java and c# call it a blockingqueue. if you have an event system you can also just put something into its message queue
|
# ? Jul 6, 2016 16:37 |
|
all i wanna do is make sure our requests to some freakin "rest" (NOT) api are sent in order. but i think they're all being sent from the same thread anyway. i don't get this c# async crap AT ALL. gotta read some more cleary
|
# ? Jul 6, 2016 17:19 |
|
Shaggar posted:functional languages are bad i also prefer non-functional languages. easier to hide the terrible programmerness.
|
# ? Jul 6, 2016 17:24 |
|
i'm just gonna try some poo poo in debug and see what happens.
|
# ? Jul 6, 2016 17:25 |
|
GameCube posted:all i wanna do is make sure our requests to some freakin "rest" (NOT) api are sent in order. but i think they're all being sent from the same thread anyway. i don't get this c# async crap AT ALL. gotta read some more cleary you want worker threads reading from a queue but if you actually want to guarantee that the requests are made in order, all of the requests need to happen in a single thread, because you can't guarantee that one worker won't pop a request off the queue and dispatch it before a previous request is dispatched. if you just want them to be mostly in order though, do a queue with worker threads the queue probably needs to be threadsafe or something idk DONT THREAD ON ME fucked around with this message at 17:34 on Jul 6, 2016 |
# ? Jul 6, 2016 17:31 |
|
comedyblissoption posted:this is the proper formatting for 4-space indentation
|
# ? Jul 6, 2016 17:32 |
|
GameCube posted:hey you terrible freaking programmers. if i've got a semaphore and one thread has been waiting on it for five minutes and then another thread comes along and waits on it the new thread might get the semaphore before the old one does. that sucks. how do i make it not do that. thanks in advance for answering my question about programming I actually thought posix semaphores already did this. rip me I guess
|
# ? Jul 6, 2016 17:38 |
|
MALE SHOEGAZE posted:you want worker threads reading from a queue i'm tryin to avoid adding threads entirely here. c# motherfucker. async all the way. my first implementation had a single task that read the stuff from the queue and sent it but gently caress that. async.
|
# ? Jul 6, 2016 17:39 |
|
o i don't really understand then
|
# ? Jul 6, 2016 17:48 |
|
Java's Semaphore class supports FIFO behavior: http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Semaphore.html#Semaphore-int-boolean-
|
# ? Jul 6, 2016 17:53 |
|
i rly like makefiles
|
# ? Jul 6, 2016 18:12 |
|
GameCube posted:i'm tryin to avoid adding threads entirely here. c# motherfucker. async all the way. my first implementation had a single task that read the stuff from the queue and sent it but gently caress that. async. but like, do you need the async? also what is your problem exactly? are you doing this kind of thing? C# code:
|
# ? Jul 6, 2016 18:17 |
|
HoboMan posted:but like, do you need the async? yeah but i just assumed that maybe sometimes func2 would finish first if i didn't put something in to prevent it. now i'm realizing that might not actually happen, so that's what i'm gonna test out
|
# ? Jul 6, 2016 18:24 |
|
btw the framework has a thread safe queue class you can use, system.collections.concurrent.concurrentqueue
|
# ? Jul 6, 2016 18:33 |
MALE SHOEGAZE posted:i rly like makefiles
|
|
# ? Jul 6, 2016 18:52 |
gonadic io posted:here's how I'd implement a Fischer-Yates shuffle. This is really good; thanks. Personally I'm cool with using flip here, since evalRandT only takes two arguments (making flip easy to reason about) and I think the increased brevity makes this a little more readable then the alternative ways of writing it. What don't you like about flip in situations like this, and what would you prefer?
|
|
# ? Jul 6, 2016 18:58 |
|
i saw some contractor code that did function signatures like this today:code:
|
# ? Jul 6, 2016 19:03 |
|
MALE SHOEGAZE posted:i rly like makefiles Maven is actually an acronym for Makefile Ant Versioning Eclipse Null
|
# ? Jul 6, 2016 19:05 |
|
VikingofRock posted:This is really good; thanks. Personally I'm cool with using flip here, since evalRandT only takes two arguments (making flip easy to reason about) and I think the increased brevity makes this a little more readable then the alternative ways of writing it. What don't you like about flip in situations like this, and what would you prefer? Using flip and an inline do-block here makes it harder to refactor, doesn't break it up in to manageable named chunks, encourages you to be "clever" with lambdas, exactly like I did for the loop etc. It's just the difference between hobby vs industry programming - in a personal project I wouldn't think twice about it. The downside of splitting it up (even just into the 3 parts like you had) is that the type inference fails so you have to write an explicit signature on the outer do block (which you called shuffled). This signature is "forall s. RandT StdGen (ST s) (Vector a)". (honestly this was a major reason why I did inline it).
|
# ? Jul 6, 2016 19:14 |
|
I like the idea of makefiles, but the reality is just horrid
|
# ? Jul 6, 2016 19:29 |
|
GameCube posted:i'm tryin to avoid adding threads entirely here. c# motherfucker. async all the way. my first implementation had a single task that read the stuff from the queue and sent it but gently caress that. async. if your code is like C# code:
if you need these to be in order then its not a candidate for async/await. You have a few options Option 1: Run the requests synchronously. C# code:
Option 2: explicit Synch after do stuff C# code:
C# code:
Shaggar fucked around with this message at 19:40 on Jul 6, 2016 |
# ? Jul 6, 2016 19:36 |
|
Soricidus posted:I like the idea of makefiles, but the reality is just horrid the concept behind makefiles is totally flawed and build scripts are retarded crap for idiots. you want a build definition that is handled by the build tool and its plugins.
|
# ? Jul 6, 2016 19:37 |
|
basically you want maven. its the only good build tool and everything else is garbage.
|
# ? Jul 6, 2016 19:41 |
|
Shaggar posted:if your code is like .Wait() is verboten so option 2 it is
|
# ? Jul 6, 2016 19:50 |
|
Soricidus posted:I like the idea of makefiles, but the reality is just horrid i don't actually use them to build things, I just like putting all of my dev tasks in there. starting containers, kicking off the actual build script, building docs, git push -f, etc i also put whatever scripts jenkins needs to run in my make file so all my jenkins jobs need to do is make foo instead of a bunch of garbage bash typed into a browser form DONT THREAD ON ME fucked around with this message at 20:00 on Jul 6, 2016 |
# ? Jul 6, 2016 19:57 |
|
I just wanna note that C# code:
C# code:
If you want to force a specific order you have to wait for the result1 at some point
|
# ? Jul 6, 2016 19:59 |
|
Shaggar posted:I just wanna note that well in three days the autistic guy is moving to a different team so maybe i'll just Wait() til then. little programmer humor there
|
# ? Jul 6, 2016 20:02 |
|
what does he have against wait()?
|
# ? Jul 6, 2016 20:15 |
|
"People fear what they don't understand and hate what they can't conquer."
|
# ? Jul 6, 2016 20:39 |
|
actually you know what I think I'm wrong here. C# code:
C# code:
|
# ? Jul 6, 2016 20:45 |
|
gonadic io posted:have the threads 1) mine bitcoins while idling and 2) use those bitcoins to incentivise the semaphore to serve them first i did that and now all my other threads that were not using semaphores before are grabbing them and holding on to them until i pay them
|
# ? Jul 6, 2016 20:45 |
|
Shaggar posted:actually you know what I think I'm wrong here. oh. that would make things a fuckload simpler
|
# ? Jul 6, 2016 20:52 |
|
Wheany posted:i did that and now all my other threads that were not using semaphores before are grabbing them and holding on to them until i pay them free market, bitch
|
# ? Jul 6, 2016 20:58 |
|
this is probably pretty simple but speaking of asynchronous operations i got a problem for it i want to make a collector type thing where multiple threads are by adding items to a queue for another thread to consume them as they come in as a java dev I've never been expected to make anything fast so this is new to me (also i'm doing this in c#) HoboMan fucked around with this message at 21:29 on Jul 6, 2016 |
# ? Jul 6, 2016 21:22 |
|
gonadic io posted:free market, bitch lockchain technology also hoboman there is probably an exact class or 2 that you can use to make that. don't ask me what they are. (because i do not know).
|
# ? Jul 6, 2016 22:20 |
|
Lutha Mahtin posted:lockchain technology
|
# ? Jul 6, 2016 22:41 |
|
well I think i accidentally started making a test harness for our webforms app this is hard
|
# ? Jul 6, 2016 22:43 |
|
|
# ? May 23, 2024 05:34 |
|
Shaggar posted:actually you know what I think I'm wrong here. yes, await blocks on the caller this tripped me up a while ago
|
# ? Jul 6, 2016 22:47 |