« first day (1250 days earlier)      last day (1594 days later) » 

4:14 AM
quick question, is it okay to handle only WM_CLOSE or should I handle both WM_CLOSE and WM_QUIT?
 
 
2 hours later…
5:48 AM
@AProgrammer I don't quite understand this? why do we need to call the clear() method on a stream before the seekg(0) method to reuse the stream?
 
 
2 hours later…
7:20 AM
@aderchox I'm missing the context. The message the chat point me to is related to FP choice of bias for the exponent.
 
7:42 AM
@AProgrammer Sorry there is no prior context. See this answer: stackoverflow.com/a/16364456/9868445, it's working for me, but the poster has not explained it clearly.
 
 
3 hours later…
10:53 AM
Would it be a good idea to template a class that's a thread-safe vector implementation? For example the code here codereview.stackexchange.com/questions/214927/…
 
@northerner sure, if you're making a wrapper for a class template then doing it with a class template seems useful
especially in the case of generic containers
 
@PeterT even if the vector needs to be able to hold type mpz_class which is from the GMP library?
 
I mean unless you want it to just hold that type I don't see how a specific type is relevant to that question
 
nwp
11:26 AM
I find it interesting that operator[] doesn't have a lock. Initially I wanted to suggest adding it, but the lock is actually useless there as it doesn't protect against anything. Only insert and push_back can be used concurrently, for everything else you need to use an external lock first which makes the class not very useful.
Additionally insert doesn't insert, it just assigns.
 
@PeterT just checking, I wasn't sure if templates would work on it because the type comes from an external library.
 
nwp
The condition variable seems to not be used anywhere. You do some notify_one, but nobody ever waits on it.
@northerner That's what templates are for. It'll work fine.
 
@nwp how should insert be implemented?
 
nwp
I don't know why you got so many upvotes. In my opinion it doesn't belong on codereview because "it doesn't work", meaning it doesn't implement a thread-safe vector.
 
ffs
 
nwp
11:30 AM
@northerner The easy way is to use std::vector::insert.
It takes an iterator instead of an index, but you can fix that with std::begin(vec) + index.
 
why wouldn't std::move work just as well?
 
nwp
I'm not sure which one you mean. The std::moves seem fine.
 
then what did you mean by "Additionally insert doesn't insert, it just assigns."?
 
nwp
I would expect SafeVector svec; svec.insert("Hi", 0); to insert "Hi" into svec at position 0. Instead it crashes because it accesses vec[0] which doesn't exist.
You seem to expect vec[index] to create an element. It doesn't.
You may have thought about std::map.
 
ok thanks for clarifying
isn't notify_one used when lock is released, which happens when method is ended?
 
11:42 AM
@northerner who are you notifying, it's a private variable, how are others supposed to wait on it
 
in another thread if it had called e.g. push_back() and was waiting for another push_back() to finish
 
I'm still not sure who's waiting on that? Are you trying to rely on some platform specific implementation where it wakes up all threads that have a mutex or something
not that that would be really great, since you're still holding the lock while calling notify
 
This was the use case I had in mind. I have multiple threads pushing information to the same vector. Order doesn't matter.
e.g. Thread 1 would add "foo" to vector and thread 2 would add "bar" to the same vector.
 
oh, ok. So it's just not implemented yet. It doesn't sound to me like you'd have enough waiters wait long enough to justify the condition variable
 
actually I see what you're saying, somethings missing
 
11:55 AM
if you would have some function like "get me the first element and if there is none, wait for there to be one" the condition_variable would make more sense
 
This code is from a long time ago I forget the details but I thought it was working
 
I mean the mutex is doing the mutual exclusion that part is working, it's just that the notify isn't really doing anything
 
That's what's confusing me. When exactly is notify_one needed vs when is just unlocking the mutex enough?
I guess it would be needed in things like the producer-consumer model: it wouldn't make sense to consume when nothings there. But in other situations it wouldn't need notify because such a state doesn't exist where one must happen before the other?
 
a condition variable is there in order to wait on some condition, you need to own the lock when starting to wait, so "wait till the mutex unlocked that I'm guarding this condition variable with" is not a valid use-case
So stuff like "there's something in the buffer" like you said in the producer-consumer sense or stuff like "wait until cache is too full to evict some older entries"
 
riiight. ok thanks
 
12:06 PM
or "wait until all the requests have finished", basically any condition that another thread may change that is more complicated than "this one lock is available"
So before we got semaphores in C++20 you're have to use condition_variable to implement semaphores yourself
 
"wait until all the requests have finished" wouldn't join() be used then?
 
you don't necessarily want to spawn a new thread if you can just re-use a worker
but yeah, you could use futures and call .get() on all of them, but let's say it's more like "only ever have 4 requests running at the same time, now get me the results for these 200 requests", but that's the producer consumer thing again I guess
 
 
3 hours later…
2:48 PM
Hi,
Need some help with cmake for generating proto files.
 
nwp
You can copy or take inspiration from this. It's been a while since I looked at it. Might be incorrect or unnecessarily verbose, but works.
 
1 message moved from Lounge<C++>
1 message moved from Lounge<C++>
 
So the problem is I have two folders
-folder1
-|- file1.proto
-folder2
-|-file2.proto
Now file2 has file1 as depedency and during file2.pb.cc generation, it says file1.bh.h not found.
 
nwp
I only have a single .proto file, so my solution probably doesn't handle that correctly.
 

« first day (1250 days earlier)      last day (1594 days later) »