Again on multithread...

This is a discussion on Again on multithread... within the C++ Programming forums, part of the General Programming Boards category; Hello, I'm looking to solve this problem. I'm programming a simple beginning application to learn multithreading under WinXP and using ...

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    106

    Again on multithread...

    Hello, I'm looking to solve this problem.
    I'm programming a simple beginning application to learn multithreading under WinXP and using VC++ and MFCs.

    My single-threaded app does a timed access to a slow data source, say 1 access every 30 secs. Every time I start the "download" it takes more than 5 seconds to be completed, and in this time the GUI is blocked.

    I was thinking to do this work by using a thread for download while the main window continues with its message pump, but I have a problem: the classes/objects that I use to do the download work are created before calling the thread, and not created by the thread, so I can't use those objects from the thread...

    How can I do? I read about syncronization mechanisms but I don't know if this is the case: how can I syncronize the access to entire objects? The thread needs to use also the thread calling object...

    Thank you for all the hints,
    BrownB

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    threads inside process same memory address

    synchronization mechanisms

    Kuphryn
    Last edited by kuphryn; 07-11-2006 at 11:57 AM.

  3. #3
    I am me, who else?
    Join Date
    Oct 2002
    Posts
    250
    You might consider using AfxBeginThread() and setting a global bool flag which lets you know when you can and cannot touch certain resources. This has worked for me, but perhaps is not the best.

  4. #4
    Registered User
    Join Date
    Oct 2003
    Posts
    106
    The problem is that is not easy understand which kind of resources/data I should check. Actually, all I need to do is to use from the thread some methods of the calling object: I'm passing to the thread the reference to the calling object (the "this" pointer) but from the thread the membres and the methods thet I see are "wrong"...

    Note that the thread main function is a static member of the calling object.

  5. #5
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    pointers not references

    post couple lines api create thread and callback function

    Kuphryn

  6. #6
    I am me, who else?
    Join Date
    Oct 2002
    Posts
    250
    I'm not sure what you mean. The thread is going to be static, yes, but when pass the "this" pointer, you can access the current class that called the thread.

    Also, when you say "wrong" I am not sure what you mean... Generally, unless this is for learning, if you are unsure what is going to be accessed or changed, you need to know that before you have a thread running.

  7. #7
    Registered User
    Join Date
    Oct 2003
    Posts
    106
    Actually I found some documentaion that says that a static method of a class can access only to static members of that class, and I tried to access to other non-static methods and members from a static method which was the thread function....

    Now, I implemented a static function as thread, and declared it as friend of the class that I want to use.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Windows Forms and multithread
    By mynickmynick in forum Windows Programming
    Replies: 4
    Last Post: 08-11-2008, 11:25 AM
  2. Multithread security problem
    By naruto in forum Windows Programming
    Replies: 2
    Last Post: 12-09-2004, 08:45 PM
  3. multithread programming in C
    By coo_pal in forum C Programming
    Replies: 3
    Last Post: 05-12-2003, 06:56 AM
  4. Multithread Mainia
    By Inquirer in forum C++ Programming
    Replies: 4
    Last Post: 10-20-2002, 11:20 PM
  5. Major Multithread Problem :: MFC
    By kuphryn in forum Windows Programming
    Replies: 1
    Last Post: 05-07-2002, 09:58 PM

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