Click here to Skip to main content
15,887,485 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionWin32 / C++ Pin
Fareed Rizkalla2-May-10 10:33
Fareed Rizkalla2-May-10 10:33 
AnswerRe: Win32 / C++ Pin
Code-o-mat2-May-10 10:48
Code-o-mat2-May-10 10:48 
AnswerRe: Win32 / C++ Pin
Michel Godfroid2-May-10 10:51
Michel Godfroid2-May-10 10:51 
AnswerRe: Win32 / C++ Pin
ThatsAlok2-May-10 20:04
ThatsAlok2-May-10 20:04 
QuestionMultithreading in general Pin
csrss2-May-10 9:22
csrss2-May-10 9:22 
AnswerRe: Multithreading in general Pin
CPallini2-May-10 9:39
mveCPallini2-May-10 9:39 
AnswerRe: Multithreading in general Pin
csrss2-May-10 9:56
csrss2-May-10 9:56 
GeneralRe: Multithreading in general Pin
Software_Developer3-May-10 2:46
Software_Developer3-May-10 2:46 



You could create an array of 8 threads 0..7, iterate in a loop and have the threads read a line each.
Remember to lock the critical section when a thread accesses line.

While (count<10)
{
 myThread[threadCount].readLineInto(myLineArray[count]);
 threadCount++;if(threadCount>7) threadCount=0;
 count++;
}


CCriticalSection cs;
 
// ThreadA writes data to an array
cs.Lock();
// Write data to an array
cs.Unlock();
....
// ThreadB reads data to an array
cs.Lock();
// Read data from an array
cs.Unlock();




Synchronized multi-threading in C++ (No MFC!)


Synchronized multi-threading in C++ (No MFC!)



class MyThread : public Thread {
private:
    int m_nCount;
public:
    MyThread(int n,const char* nm) {
        Thread::setName(nm);
        m_nCount = n;
    }
    void run() {
        for(int i=0;i<m_nCount;i++) {
            cout << getName().c_str() << ":" << i << endl;
        }
    }
};


int main() {
    Thread *t1 = new MyThread(15,"Thread 01");
    Thread *t2 = new MyThread(10,"Thread 02");
    try {
        t1->start();
        t2->start();
        t1->stop();
        t2->stop();
    }catch(ThreadException ex) {
      printf("%s\n",ex.getMessage().c_str());
  } 
  delete t1;
  delete t2;
  return 0;

AnswerRe: Multithreading in general Pin
ThatsAlok2-May-10 20:01
ThatsAlok2-May-10 20:01 
AnswerRe: Multithreading in general Pin
Rajesh R Subramanian2-May-10 23:02
professionalRajesh R Subramanian2-May-10 23:02 
AnswerRe: Multithreading in general Pin
Emilio Garavaglia3-May-10 1:23
Emilio Garavaglia3-May-10 1:23 
GeneralRe: And he would be violating the rules of threading. Pin
Software_Developer3-May-10 2:59
Software_Developer3-May-10 2:59 
GeneralRe: And he would be violating the rules of threading. Pin
Emilio Garavaglia25-Jun-10 3:04
Emilio Garavaglia25-Jun-10 3:04 
QuestionHow could I route all the windows messages of a dialog to a thread with their parameters? Pin
m_code2-May-10 8:43
m_code2-May-10 8:43 
AnswerRe: How could I route all the windows messages of a dialog to a thread with their parameters? Pin
Richard Andrew x642-May-10 8:53
professionalRichard Andrew x642-May-10 8:53 
AnswerRe: How could I route all the windows messages of a dialog to a thread with their parameters? Pin
Michel Godfroid2-May-10 8:58
Michel Godfroid2-May-10 8:58 
GeneralRe: How could I route all the windows messages of a dialog to a thread with their parameters? Pin
m_code2-May-10 9:07
m_code2-May-10 9:07 
GeneralRe: How could I route all the windows messages of a dialog to a thread with their parameters? Pin
Michel Godfroid2-May-10 9:22
Michel Godfroid2-May-10 9:22 
GeneralRe: How could I route all the windows messages of a dialog to a thread with their parameters? Pin
m_code2-May-10 9:57
m_code2-May-10 9:57 
GeneralRe: Sample code, the good way Pin
Software_Developer2-May-10 19:08
Software_Developer2-May-10 19:08 
GeneralRe: Sample code, the good way Pin
Randor 3-May-10 6:22
professional Randor 3-May-10 6:22 
GeneralRe: SendMessage is thread-safe because no interaction between the threads Pin
Software_Developer3-May-10 20:01
Software_Developer3-May-10 20:01 
GeneralRe: SendMessage is thread-safe because no interaction between the threads Pin
Randor 4-May-10 5:55
professional Randor 4-May-10 5:55 
GeneralRe: Link to an example (code) Pin
Software_Developer2-May-10 19:41
Software_Developer2-May-10 19:41 
GeneralRe: Link to an example (code) Pin
m_code4-May-10 7:28
m_code4-May-10 7:28 

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.