Thread from Dll

This is a discussion on Thread from Dll within the C++ Programming forums, part of the General Programming Boards category; Hi. I need to create a dll which starts a timer. This is easy enough, i'll just use _beginthread, increment ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    329

    Question Thread from Dll

    Hi.
    I need to create a dll which starts a timer.
    This is easy enough, i'll just use _beginthread, increment a counter for each loop, and Sleep for one second.

    The problem is, however, that i need to start multiple instances of this timer, each being able to report back to the single-threaded caller app for each tick.
    The caller also have to be able to stop the timer.
    The only return from beginthread, is the handle to the thread.

    Suggestions/hints?

  2. #2
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    So you have a begin thread function, which starts a timer thread and returns a handle.

    When the app wants to stop a timer, it calls a stop timer function and passes the handle to thread in question. This stop timer function must be thread safe.

    Presumably you want your thread to notify your application when a timer runs out. You could do this by having the DLL call a callback function in your application. You could pass the address of the callback to your DLL in the start timer function.

    However, your callback function must be thread safe because it will be called by the DLL outside of the application's main thread.

    Personally, unless there is good reason for using threads, I would implement it using poll function(s), which would be called by the application main thread at regular intervals. This would avoid the need for multiple threads & callback functions, but it may not be suitable for what your trying to do.
    OS: Windows XP
    Compilers: MinGW (Code::Blocks), BCB 5

    BigAngryDog.com

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Do you really need multiple instances of the timer?

    Could you not refer all timing queries to the same "timer"?

  4. #4
    Registered User
    Join Date
    Feb 2002
    Posts
    329

    Cool Multiple timers

    I guess i could do with a single thread, but then i would need to dynamically increase/decrease the loopcounters. I don't know how accurate this would be either. I.e. I don't know how long time it takes to perform a switch/if statement, and incrementing values in integer vars..
    I'll have to think more thoroughly about this..

    This dll is going to be an extension of a VFP program. The creator of the program says that it is going too slow using VFP timers, hence the c++ dll..

  5. #5
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    >I don't know how long time it takes to perform a switch/if statement, and incrementing values in integer vars..

    I'll think you'll find this irrelevant when compared to the fact your timer ticks are only going to be accurate to a millisecond or so.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 02-26-2008, 01:29 PM
  2. Replies: 1
    Last Post: 09-18-2005, 10:06 PM
  3. [code] Win32 Thread Object
    By Codeplug in forum Windows Programming
    Replies: 0
    Last Post: 06-03-2005, 04:55 PM
  4. multithreading question
    By ichijoji in forum C++ Programming
    Replies: 7
    Last Post: 04-12-2005, 11:59 PM
  5. Win32 Thread Object Model Revisted
    By Codeplug in forum Windows Programming
    Replies: 5
    Last Post: 12-15-2004, 08:50 AM

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