Click here to Skip to main content
15,897,187 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Cannot Open Recordset Pin
Stuart Dootson13-May-09 12:54
professionalStuart Dootson13-May-09 12:54 
QuestionNeed help about tab control!!!!!!!! Pin
happy5217713-May-09 4:46
happy5217713-May-09 4:46 
AnswerRe: Need help about tab control!!!!!!!! Pin
David Crow13-May-09 10:27
David Crow13-May-09 10:27 
QuestionApplication loses focus Pin
Tommy Svensson13-May-09 4:35
Tommy Svensson13-May-09 4:35 
AnswerRe: Application loses focus Pin
Randor 13-May-09 5:30
professional Randor 13-May-09 5:30 
AnswerRe: Application loses focus Pin
«_Superman_»13-May-09 19:09
professional«_Superman_»13-May-09 19:09 
QuestionApplication crash when application launch. Pin
Le@rner13-May-09 2:33
Le@rner13-May-09 2:33 
AnswerRe: Application crash when application launch. Pin
Cedric Moonen13-May-09 2:44
Cedric Moonen13-May-09 2:44 
GeneralRe: Application crash when application launch. Pin
Le@rner13-May-09 2:47
Le@rner13-May-09 2:47 
GeneralRe: Application crash when application launch. Pin
Cedric Moonen13-May-09 2:58
Cedric Moonen13-May-09 2:58 
GeneralRe: Application crash when application launch. Pin
Le@rner13-May-09 18:11
Le@rner13-May-09 18:11 
GeneralRe: Application crash when application launch. Pin
Cedric Moonen13-May-09 20:24
Cedric Moonen13-May-09 20:24 
GeneralRe: Application crash when application launch. Pin
Le@rner13-May-09 20:33
Le@rner13-May-09 20:33 
GeneralRe: Application crash when application launch. Pin
Cedric Moonen13-May-09 20:54
Cedric Moonen13-May-09 20:54 
QuestionRe: Application crash when application launch. Pin
David Crow13-May-09 3:13
David Crow13-May-09 3:13 
GeneralRe: Application crash when application launch. Pin
Cedric Moonen13-May-09 3:22
Cedric Moonen13-May-09 3:22 
GeneralRe: Application crash when application launch. Pin
Le@rner13-May-09 18:28
Le@rner13-May-09 18:28 
GeneralRe: Application crash when application launch. Pin
Cedric Moonen13-May-09 20:17
Cedric Moonen13-May-09 20:17 
GeneralRe: Application crash when application launch. Pin
Le@rner17-May-09 20:12
Le@rner17-May-09 20:12 
GeneralRe: Application crash when application launch. Pin
Le@rner17-May-09 20:22
Le@rner17-May-09 20:22 
QuestionAtomic operations involving __int64 on 32 bit machines Pin
Eikthrynir13-May-09 2:14
Eikthrynir13-May-09 2:14 
Hello!

Let's say we have the following:

class MyClass
{
public:
    void SetValue( __int64 a_i64Value );
    __int64 GetValue( void ) const;

private:
    __int64 m_i64Value;
};

void MyClass::SetValue( __int64 a_i64Value )
{
    m_i64Value = a_i64Value;
}

__int64 MyClass::GetValue( void ) const
{
    return m_i64Value;
}


We also have two threads: ThreadA and ThreadB, each setting the value of m_i64Value to something different.

Let's assume that ThreadA executes and SetValue is called. It writes 32 bits of m_i64Value, ThreadB executes, it calls SetValue which also writes 32 bits of m_i64Value, then ThreadA resumes and continues writing the other 32 bits of m_i64Value. Finally, ThreadB also writes the other half of m_i64Value. Eventually, m_i64Value contains garbage, invalid data.

Question 1: Is this scenario valid? Can it happen on a 32 bit machine?

Anyway, this can be solved using InterlockedExchange64, right?

But let's suppose there is a ThreadC which needs to read that value, using the member function GetValue. When returning from GetValue, 32 bits of m_i64Value get written to EAX register and 32 bits to EDX.

Question 2: What if 32 bits get written to EAX, ThreadB resumes and writes to m_i64Value and after that, ThreadC resumes and the other 32 bits (changed by ThreadB) go to EDX? Is this also a possibility on 32 bit machines? If yes, what is the best way to return such a value (__int64, in this example)?

I guess one of the solutions could be this one:

void GetValue( __int64 *a_pi64Value )
{
    if ( NULL != a_pi64Value )
    {
        InterlockedExchange64( *a_pi64Value, m_i64Value );
    }
}


Question 3: But what if we still want to actually return the value and not copy it to the memory pointed by a_pi64Value? Can this be done somehow thread-safely and using the return instruction?

Thanks in advance!
AnswerRe: Atomic operations involving __int64 on 32 bit machines [modified] Pin
Randor 13-May-09 4:47
professional Randor 13-May-09 4:47 
GeneralRe: Atomic operations involving __int64 on 32 bit machines Pin
Eikthrynir14-May-09 0:17
Eikthrynir14-May-09 0:17 
GeneralRe: Atomic operations involving __int64 on 32 bit machines Pin
Randor 14-May-09 6:59
professional Randor 14-May-09 6:59 
QuestionS.M.A.R.T support in SCSI hard disk drive Pin
Abinash Mohanty13-May-09 1:27
Abinash Mohanty13-May-09 1:27 

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.