Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > Visual C++
|
Visual C++ Questions specific to Microsoft's Visual C++. For questions not specific to this Microsoft version, use the C++ Programming forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual C++ section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 25th, 2004, 07:04 AM
Authorized User
 
Join Date: Aug 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default Alternative for while loop in thraeds

Hello,

I am new to Mulithreading. In my project I am working with multiple threads. Since I haven’t worked with threads before, I am facing many problems. Can anyone please guide me or give some hints.

I am explaining in brief about the threads used by me in my project.

1st thread: Filter Thread

Is started at application start up.
Filters each line read from file( Log data is read from file)
I have used CCriticalSection and CSingleLock to lock the data access here as this LIST is accessed in Display thread.
Adds the data to the LIST from top.
This thread has to run continuously till the application end.

2nd threadisplay Thread
Is started at application start up.
Displays each line filtered by Filter thread
I have used CCriticalSection and CSingleLock to lock the data access here as this LIST is accessed in Filter thread.
Retrieves the data from the LIST from bottom.
Deletes the data from the list after display.
This thread has to run continuously till the application end.

3rd Thread: Monitor Thread
Is started at application start up.
This thread has to continuously check if new records are added to the file ( Here another external application will add records to the file)
If new records are added, it notifies the Filter Thread, which fetches the added records, filters them and gives to Display thread for displaying.

Since all the above three threads have to run continuously, I had used sleep in all the threads as shown below.

UINT ThreadFunction(LPVOID lp)
{
while(TRUE)
{

// Do the work
}
}

The result of this is that CPU time is 100% used because of the While loop.
Can any one please suggest an alternative for while loop in the other two threads.

Thanks
Madhavi


 
Old September 29th, 2004, 06:22 AM
Registered User
 
Join Date: Sep 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello
u can use timer for that.
in the startup, set a timer using

SetTimer( 2, 100, NULL);
where 2 is the id for timer, then for every 100 millisecond, handler funtion will be called.
then, go 2 class wizard and add messagehandler
WM_TIMER.
function OnTimer(idEvent ) will be added 2 the function. write the code as u want. u can change time as u want instead of 100 ms.

HarshaPerla
http://eharsha.tk





Similar Threads
Thread Thread Starter Forum Replies Last Post
Alternative to Codeplot? pfloyd BOOK: Beginning XML, 4th Ed ISBN: 978-0-470-11487-2 21 June 5th, 2011 03:57 AM
Alternative to BOOKMARKS Shiamak Word VBA 2 October 31st, 2008 04:04 PM
Image Alternative TSEROOGY Javascript 5 December 6th, 2004 10:39 AM
alternative to MemCpy sanjaykabra82 VS.NET 2002/2003 1 September 17th, 2004 12:10 AM
Viable alternative to VS.Net pas07920 VS.NET 2002/2003 4 June 20th, 2003 05:15 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.