Multithread problems

Hello, I'm looking for a code that starting 2 process in the same moment when I run my exe file. I tried to test this code:

https://msdn.microsoft.com/en-us/library/ms682516%28v=vs.85%29.aspx

But I get this error: error: 'StringCchLength' was not declared in this scope

I don 't found this error on google and I cannot solve this problem.

Have you got some code that works on windows? Or do you know where I wrong (I paste anche copy and I have that error)

I'm using Codelite + MinGW, I tried visual C++ and I have other problems when I try to compile.

Some ideas? Thank you in advance
Works fine on MinGW. That error usually happens when you forget to include some headers.
I solved, now I can compile my source.. but I have a problem with this code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

#include <pthread.h>
#include <windows.h>
#include <winuser.h>
#include <wininet.h>
#include <iostream>
#include <fstream>
#include <ctime>
#include <string>
#include <Lmcons.h>
#include <sstream>
#include <algorithm>


#include <stdio.h>

#include <windowsx.h>

using namespace std;

////// runner

void *runner(void*)
{
     while(true){
     cout << "Hello";
    Sleep(100);
    } 
 }
/////////////////// end runner


int main() 
{
    pthread_t t1;

    pthread_create(&t1, NULL, &runner, NULL);
    

    void* result;
    pthread_join(t1,&result);

       cout << "BYE";      

}



I would that my runner (is a while loop), working in the same moment of the rest of my main program. If I compile and run this program I read only 'Hello'.
I would read Hello BYE Hello Hello Hello.

The program write 'BYE' only If I remove the loop while, and the result is Hello BYE...

do you know how i can fix this problem or same idea? I'm wronging using pthread ?!
pthread_join(t1,&result);
Joining a thrread means "wait untill it is finished". So you won't see output in main.
I suggest to move output before joining and sleep in main for some time to give thread chance to start.

And add synchronisation to the two: standard stream are not thread safe, so you will have problems if you try to write from both threads simultaneously.
I solved, I add another thread with main content, woks fine now!


Thank you!
Topic archived. No new replies allowed.