1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

implementing callbacks

Discussion in 'C++' started by oscarp, Sep 6, 2010.

  1. oscarp

    oscarp New Member

    Sep 6, 2010
    Likes Received:
    Trophy Points:
    Hi all, I'm developing a library. I would like that this library could make differents callbacks to the user part. Untill now, I had the simplest way to do it, I had stored a pointer to the user class and I was making calls when something happened, but with this implementation, if the user makes a while true in his implementation body of the callback, it will be block all my library.
    Later I thought that with threads, I'll solved this problem in a little few time but if I run a thread and I have to wait for the join, the user could block me again with the same while true.
    Later thought that a pool of threads could be my solution, but if the user makes the same while true, the worker thread will be waiting for the end of the thread, and all callbacks will be enqueue and never dequeue (correct me if I am wrong).

    The only solution that could fits me is run the callback but without waiting for the join. Is a good solution? if i pass some object to the thread, this thread, this thread has to delete memory that it doesnt alloc.

    For example:

    The users call method sends


    I have a intern queue and if is full throws a callback
    if (queueIsFull()){
      callbackQueueIsFull(message not sent)
    if the user implements his method

    void Interface::onQueueFull(message not sent){
    while true{
       trying to send message
    While the user is trying to resend my library is going to be stopped, and perhaps i'll have more messages to send or more to receive.

    Which is the best way to do this? events?


Share This Page