Click here to Skip to main content
15,914,500 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Generalconnect to lan pc for management Pin
Tony5-Oct-00 8:41
Tony5-Oct-00 8:41 
QuestionHow to restore users Visual Studio profiles on WinNT4 Pin
adilo045-Oct-00 7:56
adilo045-Oct-00 7:56 
GeneralConvert BSTR into LPSTR Pin
gupta5-Oct-00 6:18
gupta5-Oct-00 6:18 
GeneralRe: Convert BSTR into LPSTR Pin
Michael Dunn5-Oct-00 7:19
sitebuilderMichael Dunn5-Oct-00 7:19 
QuestionHow to change the language in my application Pin
Anonymous5-Oct-00 3:09
Anonymous5-Oct-00 3:09 
QuestionHow to IMPLEMENT a Mutex in C++ ? Pin
GBO5-Oct-00 2:06
GBO5-Oct-00 2:06 
AnswerRe: How to IMPLEMENT a Mutex in C++ ? Pin
Erik Funkenbusch5-Oct-00 7:52
Erik Funkenbusch5-Oct-00 7:52 
GeneralUpdate: How to IMPLEMENT a Mutex in C++ ? (Assembler Guru required) Pin
GBO5-Oct-00 21:42
GBO5-Oct-00 21:42 
A Problem with the previously mentioned algorithms is that they assume "atomic" read and write operations.

I also found this solution which is, like you say is dependent on "undividable" processor instructions.

// ALGORITHM
////////////
// wait(s)
// { set s = 0 and if old value of s was 0 then
// repeat
// 'wait'
// until set s = 0 and old value of s was 1 }
// signal(s)
// { s = 1; Tell OS if appropriate }

Concerning, "how are you getting multiple threads if you don't have an OS?".

From my perspective (WinNT/W2K backend programmer, now engaged in building software for a NO-OS device), the device we are building has two "tasks" ("Threads").
It has a slow main loop (task 1) which can be 'interrupted' ("pre-empted") by the driver level (task 2..N).
The idea is to have the driver level handle the Hardware dependent stuff, e.g. detect if a keypad button that was pressed, and put it in an event queue for the slow main loop to process.
If my main loop can get interrupted at any time, I need some protection (locking) on the queue, otherwise it will get corrupted. (if it is locked by the main loop, I could put the event in a temporary queue and put it in the real queue some time later (ASAP of course) )

The standard way of avoiding corruption is:

mutex_begin()
{
disable_interrupts();
}

mutex_end()
{
enable_interrupts();
}

Which of course could lead to "event loss".

The algorithm above (based on TestAndSet) is an improvement over this, but it needs to be supported by processor instructions.
Since I am not a whizz kid in assembler (let's be honest, I never had to use it before so I never did), I am gratefull for any pointers or assembler crash courses that anyone can give me about these undividable SMP safe (i386) instructions I could use to implement a Test And Set function.

// MSDN example
int power2( int num, int power )
{
__asm
{
mov eax, num ; Get first argument
mov ecx, power ; Get second argument
shl eax, cl ; EAX = EAX * ( 2 to the power of CL )
}
/* Return with result in EAX */
}

// my would-be function that sets a value (nValue) on the target address (pTargetAddress) and returns the previous value (that was found in pTargetAddress)
int testandset(int* pTargetAddress, int nValue)
{
__asm
... // help !
}

Best regards,

Gert.
GeneralRe: Update: How to IMPLEMENT a Mutex in C++ ? (Assembler Guru required) Pin
GBO5-Oct-00 23:32
GBO5-Oct-00 23:32 
QuestionFace Recognition Software? Pin
Jeremy Davis4-Oct-00 23:19
Jeremy Davis4-Oct-00 23:19 
GeneralHelp with colors in MFC, damn I'm bad at painting :) Pin
Fredrik4-Oct-00 21:53
Fredrik4-Oct-00 21:53 
GeneralRe: Help with colors in MFC, damn I'm bad at painting :) Pin
Jeremy Davis4-Oct-00 22:13
Jeremy Davis4-Oct-00 22:13 
GeneralAnyone got any idea of how to do this? Pin
Fredrik5-Oct-00 21:34
Fredrik5-Oct-00 21:34 
GeneralRe: Anyone got any idea of how to do this? Pin
Jeremy Davis5-Oct-00 22:22
Jeremy Davis5-Oct-00 22:22 
QuestionHow to hide main dialog Pin
Crystal4-Oct-00 17:44
Crystal4-Oct-00 17:44 
AnswerRe: How to hide main dialog Pin
Sam Hobbs4-Oct-00 18:30
Sam Hobbs4-Oct-00 18:30 
GeneralSTL Collection Classes Pin
paulb4-Oct-00 17:19
paulb4-Oct-00 17:19 
GeneralRe: STL Collection Classes Pin
Erik Funkenbusch5-Oct-00 8:03
Erik Funkenbusch5-Oct-00 8:03 
GeneralRe: STL Collection Classes Pin
Erik Funkenbusch5-Oct-00 8:17
Erik Funkenbusch5-Oct-00 8:17 
GeneralRe: STL Collection Classes Pin
Norbert Muench6-Oct-00 3:29
sussNorbert Muench6-Oct-00 3:29 
GeneralCustomize Open File Dialog Pin
Farzad Bakhtiar4-Oct-00 17:01
sussFarzad Bakhtiar4-Oct-00 17:01 
GeneralToolBar Pin
kin4-Oct-00 16:21
kin4-Oct-00 16:21 
GeneralRe: ToolBar Pin
Member 12089655-Oct-00 11:45
Member 12089655-Oct-00 11:45 
GeneralSize of the Single Document Pin
sunny4-Oct-00 14:28
sunny4-Oct-00 14:28 
GeneralRe: Size of the Single Document Pin
Michael Dunn4-Oct-00 15:48
sitebuilderMichael Dunn4-Oct-00 15:48 

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.