How to bind a thread to same message queue as original?

This is a discussion on How to bind a thread to same message queue as original? within the Windows Programming forums, part of the Platform Specific Boards category; I was wondering how it might be possible to bind a new thread to the message queue of the original ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    75

    Post How to bind a thread to same message queue as original?

    I was wondering how it might be possible to bind a new thread to the message queue of the original thread or the one that called CreateThread(). I'm not sure if this is even possible but perhaps there is a better workaround then having to share some data structures between the threads that would be making the messages available to both of them. I know too little about multi-threading in order to prevent race conditions and such. Also that solution isnt very elegant in my opinion. I looked on MSDN but I didn't find many answers. I think they never expect you to do something like that.

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    I suspect if you want to do this, then you have a design issue. What is it you are trying to acheive?

    Under Windows, controlling access to sensitive data in a multithreaded environment is really quite easy, don't be afraid of it.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    I would tend to agree with adrian that this could probably be coded around......if you are chanelling the activity of 1 thread through another, what's the benefit of 2 threads!??!

    You could use a mock message loop in the second thread and then instead of calling SendMessage(), you could use PostThreadMessage() to send the message back to the "processing" thread.....not sure how affective this would be though....or if its advisable...

    Also, for thread synch....look up the CRITICAL_SECTION as a way to syncronise thread access......I did an example of this on this board a while (well it was a pretty ham-fisted by my own admission!, but it may give an idea).....if you are interested, do a search

  4. #4
    Registered User
    Join Date
    Jan 2002
    Posts
    75
    Hmm. Yes. Well here is what I'm trying to do: I want to make a little package for our school for AP Computer Science. I myself have finished the course, but for next year. Basically the package would operate in a normal console-mode program that would include a header file interface and additional cpp file which would then allow the user to invoke fully functional windows with little programming experiance. I did happen to find a function that should work for mapping thread input to another thread (AttachThreadInput()), however I haven't tried it yet. Anyways, I'm desiging it to be easier to use than for example CMUgraphics from carnegie-mellon. We found that very confusing and difficult to compile in class. Also, I wanted the package to have support for three ways of setting up input from th windows. A) linear, as in window.wait_charpress(). B) callback functions to introduce the programmer to event-mode programming. C) inheritance and virtual functions to introduce the programmer to polymorphism. I happen to have this kind of setup in my mind, but I want it to be more clear before I actually start making it. I have never made a final program without it being sloppy because I will dive into making code. I'm sure you guys know how it is.

    Feel free to comment or make suggestions. It would probably help out. Thanks

    And as kind of a side issue, how might someone use namespaces practically? I've never found a situation where namespaces were more practical than simply annoying since I always see everyone using the 'using' keyword.
    Last edited by genghis; 06-01-2002 at 05:06 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 02-26-2009, 11:48 PM
  2. Fixing my program
    By Mcwaffle in forum C Programming
    Replies: 5
    Last Post: 11-05-2008, 03:55 AM
  3. Queue implementation
    By kolliash in forum C Programming
    Replies: 1
    Last Post: 06-01-2008, 09:25 AM
  4. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  5. New Thread with same Message Queue?
    By genghis in forum Windows Programming
    Replies: 2
    Last Post: 01-31-2002, 06:17 PM

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