« first day (1222 days earlier)      last day (1631 days later) » 

10:09 AM
can you give an example usecase of a lambda that is giving you an access violation?
 
@ratchetfreak

I have a class with a member Model* m_Model;
In another member function there's a call to a Post request and the response is handled in a lambda


PostAPI(url, [this](auto &responseBody) {
m_Model->m_Map = ParseResponse(responseBody);
...

The assignment operation throws the access violation
 
is m_Model initialized at the point the lambda gets called?
and does this survive at the same location until the lambda gets called?
 
10:30 AM
m_Model is initialized in the constructor
I've been wondering about the survival of this. I'm not sure why it wouldn't as the class seems to not get destructed as far as I checked. It is being held in an application instance that gets created by a framework.
It is strange that I can perform something like m_Model->m_Map.size() but once I modify or clear() I get the violation
 
10:47 AM
does it get moved?
 
not by me at least. how can I check that?
 
Does anyone know what the proper way be in cmake to build relocatable object file, i.e. ld -r ?
 
@Ramzis you can define the move constructor/assign operator (along with the other rule of 5 stuff) and make it log each event
 
11:22 AM
@ratchetfreak I defined all 5 and it seems the move assignment one was being called. Now that it is defined it doesn't crash. So what happened here?
 
use after free I think,
if you replace the `Model* m_Model;` with `std::unique_ptr<Model> m_Model;` (and the same with all the other pointer members) it should also be fixed
 
12:06 PM
I tried changing the pointers into unique_ptr for the members of the class container class but it still gives the error. The issue somehow lies in the class itself which is an object. If I comment out this

ContainerClass& operator=(ContainerClass&& other) // move assignment
{
return *this;
}

it breaks but otherwise works fine. Why isn't this just implicit?
 
move assignment should move all the members from other to this
 
just set a breakpoint in the move assignment operator and figure out why it's moving it via the call-stack
 
if I get your issue then the sequence of events is postApi -> move -> callback -> accessviolation
 
12:32 PM
What is event loop? Is event loop a desgin pattern related to poll family function?
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <netdb.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <poll.h>

#include <arpa/inet.h>

#define PORT "9034"  // the port client will be connecting to
#define BUFSIZE 256

void *get_in_addr(struct sockaddr *sa)
{
    if (sa->sa_family == AF_INET) {
        return &(((struct sockaddr_in*)sa)->sin_addr);
    }

    return &(((struct sockaddr_in6*)sa)->sin6_addr);
Is this a classic event loop example?
The code sample basically uses a poll to monitor socket input from server and standard input from client, which I think I can also achieve that with 2 sperate threads or processes, one blocked for TCP socket and one for standard input.
 
12:52 PM
yeah the event loop is essentially while(true){e = waitForEvent(); dispatchEvent(e);}
poll is a function that lets you wait for events on file descriptors
 
1:04 PM
The move was actually happening before post api.
Coming from c# I thought the object required a Container c = Container() which was causing the move assignment. Removing that line, since the object gets (apparently) constructed in the header declaration by default, solved the issue.
It is still interesting to ponder about it why the class became invalid if I did have that line.

Is "move assignment should move all the members" a general thing to do when creating a custom class? I.e. is copying of all members not implicit even if they are just objects and not pointers?
 
1:15 PM
@ratchetfreak Ok. Is poll like function a must-have for a event loop design? I mean, as for the example above , I can also use 2 threads or processes, one blocked(wait) for socket input from server and another blocked for standard input.
Is the latter I described also a legal event loop design?
 
1:33 PM
@Ramzis if you define the move assignment you take over responsibility for the entirety of the move
@Rick I find that kind of ratholing discussion meaningless pedantry
but each thread does have an eventloop waiting on just one kind of event
 
Ok. Would it be more appropriate if I ask in this way:
What do I benefit from the poll design pattern, compared to the latter one?
 
fewer threads and less inter-thread synchronizations required
 
That's the actual question coming up in my mind today when I realize that I can probably achieve the same thing with multithreads / multiprocesses.
Great!
So is that the main reason that makes the poll family functions so different and significant?
 
yeah, threads are not free, and definitely not cheap enough to warrant having one per blocking operation
thread synchronization isn't all that cheap either
 
Ahhhh! Ok I see , that's it. Really thank you for the explanation. I had been wondering what exactly benefit that poll family functions give us.
You know, people always talk about how great and important poll is but doesn't give an example and comparsion.
Yes, for multithreads or processes I need to handle all the synchronization problems. Mutex sort of thing.
Also need to worry about atomic operation issues for function calls.
 
1:49 PM
@ratchetfreak Gor Nishkov did a nice paper discussing this, stackful coroutines (fibers) and stackless coroutines.
 
 
10 hours later…
ggg
11:29 PM
void Network::string_to_char(std::string str, char* data){
strcpy(data, str.c_str());
}
how come this gives error but if i put a cout before or after the strcpy it works?
the error is "terminate called after throwing an instance of 'std::length_error'
what(): basic_string::_M_create
Aborted (core dumped)"
 

« first day (1222 days earlier)      last day (1631 days later) »