Problem with a multithreaded program

This is a discussion on Problem with a multithreaded program within the C++ Programming forums, part of the General Programming Boards category; This is the code: Code: #include <cstdlib> #include <iostream> #include <process.h> #include <windows.h> using namespace std; void Func1(void *P); void ...

  1. #1
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318

    Problem with a multithreaded program

    This is the code:
    Code:
    #include <cstdlib>
    #include <iostream>
    #include <process.h>
    #include <windows.h>
    using namespace std;
    void Func1(void *P);
    void dramatic(void *P);
    CRITICAL_SECTION Section;
    int main(){
    InitializeCriticalSection(&Section);
    _beginthread(Func1,0,NULL);
    _beginthread(dramatic,0,NULL);
    Sleep(5000);
    DeleteCriticalSection(&Section);
    return 0;
    }
    void Func1(void *P){
    int Count;
    for(Count=1;Count<11;Count++){
    EnterCriticalSection(&Section);
    cout<<"Func1 loop "<<Count<<endl;
    LeaveCriticalSection(&Section);
    }
    void dramatic(void *P){
    int Count;
    for(Count=1;Count>0;Count++){
    EnterCriticalSection(&Section);
    cout<<"Func1 loop "<<Count<<endl;
    LeaveCriticalSection(&Section);
    }
    return;
    }
    Log:
    Code:
    Kompilaator: Consoles
    Building Makefile: "C:\Programs\Dev-Cpp\Makefile.win"
     make... käivitus
    make.exe -f "C:\Programs\Dev-Cpp\Makefile.win" all
    g++.exe -c Templates/process.cpp -o Templates/process.o -I"C:/PROGRAMS/DEV-CPP/lib/gcc/mingw32/3.4.2/include"  -I"C:/PROGRAMS/DEV-CPP/include/c++/3.4.2/backward"  -I"C:/PROGRAMS/DEV-CPP/include/c++/3.4.2/mingw32"  -I"C:/PROGRAMS/DEV-CPP/include/c++/3.4.2"  -I"C:/PROGRAMS/DEV-CPP/include"   
    
    Templates/process.cpp: In function `void Func1(void*)':
    Templates/process.cpp:24: error: a function-definition is not allowed here before '{' token
    
    Templates/process.cpp:24: error: expected `,' or `;' before '{' token
    
    Templates/process.cpp:32: error: expected `}' at end of input
    
    Käivitus peatatud

  2. #2
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Looked the code for 10 minutes to find the mistake, and I found it just after posting!
    Hehe

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,047
    What was the mistake? Was it related to indentation?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,047
    Oh, never mind, I see it. It was related to indentation.

    Code:
    void Func1(void *P){
    int Count;
    for(Count=1;Count<11;Count++){
    EnterCriticalSection(&Section);
    cout<<"Func1 loop "<<Count<<endl;
    LeaveCriticalSection(&Section);
    }
    void dramatic(void *P){
    Not enough closing braces.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem w/ doubles in friend's program
    By mkylman in forum C Programming
    Replies: 16
    Last Post: 11-22-2008, 09:45 AM
  2. I have finished my program, one problem
    By sloopy in forum C Programming
    Replies: 4
    Last Post: 11-29-2005, 01:10 AM
  3. Replies: 20
    Last Post: 06-12-2005, 11:53 PM
  4. Console Program Problem
    By Breach23 in forum C++ Programming
    Replies: 3
    Last Post: 10-19-2001, 12:35 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21