Click here to Skip to main content
16,011,839 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Alternative for while loop in threads Pin
Andrzej Markowski25-Sep-04 4:59
Andrzej Markowski25-Sep-04 4:59 
GeneralRe: Alternative for while loop in threads Pin
ledallam27-Sep-04 20:51
ledallam27-Sep-04 20:51 
GeneralRe: Alternative for while loop in threads Pin
Andrzej Markowski28-Sep-04 7:40
Andrzej Markowski28-Sep-04 7:40 
GeneralRe: Alternative for while loop in threads Pin
ledallam28-Sep-04 18:09
ledallam28-Sep-04 18:09 
GeneralRe: Alternative for while loop in threads Pin
JimmyRopes25-Sep-04 16:51
professionalJimmyRopes25-Sep-04 16:51 
GeneralThread - check continously Pin
ledallam25-Sep-04 0:25
ledallam25-Sep-04 0:25 
GeneralRe: Thread - check continously Pin
Brad Bruce25-Sep-04 1:21
Brad Bruce25-Sep-04 1:21 
GeneralRe: Thread - check continously Pin
JimmyRopes25-Sep-04 4:59
professionalJimmyRopes25-Sep-04 4:59 
You can use a kernel mode synchronization object, i.e. event or mutex. You can also use a semaphore and set the max count to 1 and it will act like a mutex but then why not use a mutex.

Basically what you need to do is acquire the event or mutex in the code updating the file so that no one else can get it. After the object is acquired you start the monitor thread and attenpt to obtain the object in that thread. The monitoring thread will block and not be eligable for scheduling again until the object is acquired which will not happen until the file process thread releases it after making an update to the file. After a short wait, 1 or even 0 microseconds, to insure the file processing thread gives up the remainder of it's timeslice thus insuring that the object is acquired by the waiting file monitoring thread, attempt to obtain the object again in the file processing thread.

The file monitor then wakes up, does what it does and releases the object so that the file processing thread can get it again. Since the file processing thread is queued up to get the object you can try to acquire the object again in the monitoring thread after a short wait so that the monitoring thread gives up the remainder of it's time slice to insure that the file processing thread will obtain the object. In this way the monitoring thread will be blocked and not using CPU cycles until it comes to life when the file processing thread releases the object.

This will work even if the file processing thread is in a different process than the monitoring thread. Note that all the threads have to be executing at the same dispatch priority for this logic to work properly.

The important thing to remember is to relinquish the remainder of the threads time slice before trying to acquire the object again thus insuring that the other thread is able to get the object.

If more than two threads are involved in the logic you will need to use a memory mapped file or additional, uniquely named, kernel mode synchronization object(s) to exchange state information between processes so that they know when to attempt to obtain the object.

You will have to insure that the object name is unique between all processes so it is best to use either the guidgen or uuidgen programs to generate a unique identifier for use in the object's name. I would also include a user friendly prefix or suffix so if you use a spy program to debug the interaction between these threads you will be able to recognize the the object by it's name.

QuestionWindow class in Dll. Help me to find the problem ? Pin
AlexanderKhilko25-Sep-04 0:22
AlexanderKhilko25-Sep-04 0:22 
GeneralOpen Dialog problem Pin
Plons24-Sep-04 23:27
Plons24-Sep-04 23:27 
GeneralRe: Open Dialog problem Pin
Gary R. Wheeler25-Sep-04 2:33
Gary R. Wheeler25-Sep-04 2:33 
GeneralRe: Open Dialog problem Pin
Plons26-Sep-04 5:29
Plons26-Sep-04 5:29 
Generalhidding a file for good Pin
gamitech24-Sep-04 23:27
gamitech24-Sep-04 23:27 
GeneralRe: hidding a file for good Pin
Brian Delahunty25-Sep-04 0:12
Brian Delahunty25-Sep-04 0:12 
GeneralRe: hidding a file for good Pin
Moak26-Sep-04 23:15
Moak26-Sep-04 23:15 
GeneralEN_CHANGE Pin
gamitech24-Sep-04 23:06
gamitech24-Sep-04 23:06 
GeneralRe: EN_CHANGE Pin
Andrzej Markowski24-Sep-04 23:44
Andrzej Markowski24-Sep-04 23:44 
GeneralRe: EN_CHANGE Pin
Andrzej Markowski3-Oct-04 16:31
Andrzej Markowski3-Oct-04 16:31 
Generalproblem with NT service Pin
JimmyRopes24-Sep-04 23:04
professionalJimmyRopes24-Sep-04 23:04 
GeneralRe: problem with NT service Pin
ThatsAlok24-Sep-04 23:26
ThatsAlok24-Sep-04 23:26 
GeneralRe: problem with NT service Pin
JimmyRopes25-Sep-04 3:38
professionalJimmyRopes25-Sep-04 3:38 
GeneralRe: problem with NT service Pin
Blake Miller27-Sep-04 12:18
Blake Miller27-Sep-04 12:18 
GeneralRe: problem with NT service Pin
JimmyRopes27-Sep-04 18:45
professionalJimmyRopes27-Sep-04 18:45 
GeneralProblem with Serial communication Pin
Jbardo24-Sep-04 22:50
Jbardo24-Sep-04 22:50 
GeneralSetting attributes to CFile Pin
ledallam24-Sep-04 20:47
ledallam24-Sep-04 20:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.