« first day (497 days earlier)      last day (2339 days later) » 

5:20 AM
Hey guys, just wondering about this specific description about std::thread::detach()::
"Separates the thread of execution from the thread object, allowing execution to continue independently"
Does this mean that the std::thread object no longer needs to manage the lifetime of the actual thread; i.e. it can keep on running even after the object has been destroyed?
I would guess that of course the actual thread would die when the main function is exited out of main thread as well, but I just wanted to make sure of this^
 
 
2 hours later…
nwp
7:50 AM
@OneRaynyDay Yes.
@OneRaynyDay I remember it being bad when that happens. I forgot the specifics.
Losing the ability to tell when a thread ends and it being bad when the main thread ends without the other threads makes .detach mostly useless. The only situation in which I imagine it being useful is when you make some sort of service that is intended to run forever and doesn't support exiting at all.
 
 
6 hours later…
1:56 PM
@nwp you can easily replace the join with detach+thread synchronization of course
 
nwp
If you do something like signal_thread_exit(); and then return from the thread function in the thread and you then receive the signal in another thread you still technically can't be sure that the thread exited or is still destructing local variables or doing whatever other things that might take arbitrarily long.
Essentially you have a race and hope the timing will work out, which is not a good way to do multi threading.
 
@nwp it's easy to limit the scope of said locals to before the signaling. Also en.cppreference.com/w/cpp/thread/promise/… and friends
I agree that .detach() is rarely useful (it merely facilitates laze, IYAM) but it's not impossible to use correctly
 
nwp
@sehe That's pretty cool. Never seen that.
 
2:12 PM
I'm very confused by memcpy
I've got a uint8_t mydata[] and I'm trying to my sensor data in it
how do I do this
 
nwp
@MaartenWachters Trying to access?
What format are they in?
 
uint8_t
 
he means what does each byte mean
 
memcpy(dest, src, size_in_bytes)
 
nwp
@MaartenWachters Why would you need memcpy then? Just do mydata[0] and so on to access the data.
 
2:17 PM
    uint8_t mydata[] = "";
    uint8_t degree = 100;
    memcpy(mydata[], degree, sizeof(mydata[]);

results in an exit status 1
 
nwp
You are supposed to pass pointers.
 
mydata[index++] = degree;
 
this shouldn't even compile
 
nwp
&degree at least. And sizeof should take the smaller size and degree is pretty small.
 
once index is equal to the size of mydata then you need to purge some old data
 
2:35 PM
hmm
cant seem to fix it
You reckon changing it to a byte would be easier
 
nwp
Showing a bigger piece of the code would help. Ideally put it on coliru and try to get it to compile and show the problem you are having.
 
That link complains about libraries
 
create stubs for those functions or remove if they are not relevant to the example
 
nwp
Are the libraries important? Maybe you can replace your sensor with int get_sensor_data() { return 42; }.
 
Uhh I'm not home in this
Just tryna get my lorawan to send custom sensor data
 
2:41 PM
we want to see a SSCCE
 
 
1 hour later…
4:01 PM
For my problem of limit id's in each level of my scene graph i have an other approach. Maybe to track at runtime, which ids are used and which not. Maybe a logic that provide a "free" id on node creation.
 
4:16 PM
@ratchetfreak you have a tip for me ?
 
if you don't expect actions to exceed 2 billion then keep a nextID and return nextID++;
compact them on save
 
"if you don't expect actions to exceed 2 billion" :-) no way
 
4:56 PM
 
yeah something like that
 
5:12 PM
and when the boundary is reached ?
 
you probably won't have 2 billion nodes so you can do a compaction pass (or sidestep the issue by starting with 64 bit IDs)
compaction can be done by going over every node and giving them a new ID starting from 1. Then going over every node again and reassigning references to use the new ID
 
@nwp This can happen?
 
nwp
5:27 PM
@OneRaynyDay That the main thread exits before some other thread? Sure.
 
@nwp not that; I meant that the detached thread will keep running even though the main thread has exited
 
nwp
I don't remember. I think it's UB.
 
I would assume that there's some internal library that ensures proper cleanup of detached threads at the termination of the program, otherwise it's the leakiest of memory leaks
 
nwp
96
Q: What happens to a detached thread when main() exits?

Marc Mutz - mmutzAssume I'm starting a std::thread and then detach() it, so the thread continues executing even though the std::thread that once represented it, goes out of scope. Assume further that the program does not have a reliable protocol for joining the detached thread1, so the detached thread still runs...

No clear answer.
 
5:44 PM
"any thread, whether detached or not, will die with its process on most OSes" <-- found it amidst much text :P
 
nwp
Now you just need to figure out if you are on one of those unspecified OSs.
 
@nwp I'm sure if I'm running on anything sane it should be alright :)
 
6:02 PM
@nwp That's because the standard doesn't directly address the question, and what it implies runs directly contrary to how essentially all known OSes actually work.
 
Grinding on C++ for the past few days; attempting to interview at Mysticial's firm
Any suggestions for books other than Scott Meyers and Concurrency In Action?
(I know I'm not on the same caliber as Mysticial; I'm an intern while he's probably a higher-up researcher)
 
nwp
From what I heard from mystical I wouldn't want to work there.
Unless I really needed money.
It's that finance/bank firm right?
 
Yes. I don't have a work life balance, and I think it's a really good place to learn C++ and be working with some hardcore smart people
so I think it's more catered for people like me :P
 
nwp
You could think about learning a bit about the domain. Like how high frequency trading works, why performance is so important, that they invert the "goal function" in simulations so it quickly loses massive amounts of money in order to test it, that some company forgot to revert the inversion and so on.
Might help connecting or something.
Probably also know about profiling.
 
I definitely would not say I'm an expert at that domain, but I think I have a pretty general idea of why they would need performance/multithreading/etc.
HFT uses C++ instead of Java probably because the GC in java does a global lock and halts the entire program; and those 2 milliseconds counts a lot for HFT. In C++ you can expect general similar throughput and the free'ing must take slightly longer but you'd expect everything that's happening
They run tons of monte carlo simulations on some big mainframes to get their algo down. But they need to take in large amounts of requests @ once and process them and decide as fast as possible so it's crucial that they have multithreaded applications w/ threadpools at standby & some throttling implemented, etc
if you ask me to get into the weeds though, I would throw up my hands because I don't know much there
 
nwp
6:18 PM
Be careful about making claims that are difficult to back up. Some executive might say "Java is overall faster? You can disable the GC right? Lets make some money!".
 
That's true :o it's a bit controversial huh; I do think that some firms do use Java, but I would think the ultimate argument is that c++ is just closer to the hardware, and whatever you can do in java you can do in c++, no?
and I know some things in Java are just slower than c++; for example generics are runtime constructs while templates are compile-time, but this allows them to actually be able to read their errors rather than a spew of garbage
 
6:42 PM
@OneRaynyDay I don't think there's much controversy--HFT has used C++ almost exclusively for long enough that I doubt most of them even consider using Java (at least for the main part of the trading platform itself--maybe for other utilities and such).
@OneRaynyDay ...but it also means their errors (some of them, anyway) happen at run-time instead of compile-time.
 
@JerryCoffin So it's more of a historical thing?
 
@OneRaynyDay At this point, yes, probably. But it's not like the typical use of "historical" or "legacy", where it's really a cover for doing the wrong thing. In this case, it's more like: "why do cars use wheels?" On one hand, it's been that way forever, and almost nobody really thinks about alternatives. At the same time, most of the reason it's been that way forever is that alternatives have been tried and failed--and circumstances haven't changed enough to believe another attempt will succeed.
 
@JerryCoffin I see. That makes a lot of sense :) I heard jane street's doing something interesting with OCaml though; perhaps that's a cool attempt
 
@OneRaynyDay OCaml at least brings something different to the table. At least offhand, it doesn't seem like most of what Java adds (e.g., most of its standard library) is likely to be at all relevant to an HFT platform.
 
@JerryCoffin I see, thanks! :) I don't know too much about Java's stdlib to comment, but it would seem like Java's usage is still in the server backend industry
 
 
3 hours later…
9:57 PM
Hey guys, from what I'm reading, I see that a condition_variable in c++11 can perform a "spurious wake"
why did anyone decide "spurious wakes" were a good idea? It just sounds like the conditional variable just randomly decides to wake threads up and test for the conditional function that's passed into wait()
why not just wait their turn proper, and only check during cond_var.notify_one()?
 
10:50 PM
@OneRaynyDay One common possibility arises when an POSIX signal happens in the middle of a wakeup event. If the signal is delivered to the waiting thread, the call to pthread_cond_wait will return, so it can service the signal. Then the thread re-calls its wait, and waits until the condvar is really signaled.
There are also race conditions where (for example) you clear the mutex and immediately afterward notify the cond var. If somebody else was waiting on the mutex, they could wake up, and reset the variable, so by the time the thread waiting on the cond var wakes up, the condition is no longer true.
 
11:16 PM
@JerryCoffin So happy you're around here. I couldn't have articulated that quite so well
 
@sehe I'm around everywhere (but I've been trying to diet, so maybe I'll be a little less round for a little while).
 
Clbuttic Coffin
 

« first day (497 days earlier)      last day (2339 days later) »