Event driven thread programming

This is a discussion on Event driven thread programming within the C++ Programming forums, part of the General Programming Boards category; Hi. I'm fairly new to c++ so bear with me What i'm trying to code is an event driven register/dispatch ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    10

    Event driven thread programming

    Hi. I'm fairly new to c++ so bear with me

    What i'm trying to code is an event driven register/dispatch system for dealing with incomming data from a socket. I have got the sockets bit figured out, but the next step is giving me a headache.

    I want a registration method which invokes a new thread for each registered event and loops while checking for new data. When data corresponding to that event arrives it should send it to this thread whose loop will pick up the data from a queue and deal with it accordingly.

    I was wondering if it was possible to pass a pointer to a function, which could then be executed when its corresponding event occurs. Or if not, does anyone know of a thread-safe framework for acheiving this kind of event driven program?

  2. #2
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    And you're new to C++?
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  3. #3
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    I was wondering if it was possible to pass a pointer to a function, which could then be executed when its corresponding event occurs.
    It is possible.

    but implementation in most cases will be platform dependent... so better to ask on the corresponding board and list some details like OS, Compiler, etc
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  4. #4
    Registered User
    Join Date
    Nov 2006
    Posts
    10
    Quote Originally Posted by vart
    It is possible.

    but implementation in most cases will be platform dependent... so better to ask on the corresponding board and list some details like OS, Compiler, etc
    I'd like to keep it as platform-independant as possible as it must compile in both windows and linux. I dont mind switching a few header files or minor adjustments to system functions, but the overall framework must produce the same result.

    That is why I am compiling in mingw for windows and gcc for linux, and i'm using the boost::threads library for the threading part.

  5. #5
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,412
    Since you are with boost already, I believe a portable solution is the boost::signal library.

    http://www.boost.org/doc/html/signal...html#id2731417
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  6. #6
    Registered User
    Join Date
    Nov 2006
    Posts
    10
    Quote Originally Posted by Mario F.
    Since you are with boost already, I believe a portable solution is the boost::signal library.

    http://www.boost.org/doc/html/signal...html#id2731417
    Perfect, Thanks

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    If you're dealing with sockets, an even better way is to use Boost.Asio, which pretty much does what you want.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to organize an event driven system
    By Marksman in forum C++ Programming
    Replies: 2
    Last Post: 02-04-2008, 05:11 PM
  2. C++ Threading?
    By draggy in forum C++ Programming
    Replies: 5
    Last Post: 08-16-2005, 12:16 PM
  3. [code] Win32 Thread Object
    By Codeplug in forum Windows Programming
    Replies: 0
    Last Post: 06-03-2005, 03:55 PM
  4. multithreading question
    By ichijoji in forum C++ Programming
    Replies: 7
    Last Post: 04-12-2005, 10:59 PM
  5. Replies: 12
    Last Post: 05-17-2003, 05:58 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21