I've wrote this code:
#include <iostream>
#include <thread>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
const int mx = 1e9;
void f(int l, int r, int *res)
{
int c_3, c_5;
c_3 = c_5 = 0;
for (int i = l; i < r; i++)
{
if (!(i % 3)) c_3++;
if (!(i % 5)) c_5++;
}
*res = c_3 + c_5;
}
void s(int l, int r, int *res)
{
int c_3, c_5;
c_3 = c_5 = 0;
for (int i = l; i < r; i++)
{
if (!(i % 3)) c_3++;
if (!(i % 5)) c_5++;
}
*res = c_3 + c_5;
}
int main()
{
int res1, res2;
thread th1(&f, 0, mx / 2, &res1);
thread th2(&s, mx / 2, mx, &res2);
th1.join();
th2.join();
cout << res1 + res2;
return 0;
}
And I have following error:
/usr/bin/ld: /tmp/cc3k2P1B.o: in function `std::thread::thread<void (*)(int, int, int*), int, int, int*, void>(void (*&&)(int, int, int*), int&&, int&&, int*&&)':
main.cpp:(.text._ZNSt6threadC2IPFviiPiEJiiS1_EvEEOT_DpOT0_[_ZNSt6threadC5IPFviiPiEJiiS1_EvEEOT_DpOT0_]+0x43): undefined reference to `pthread_create'
/usr/bin/ld: /tmp/cc3k2P1B.o: in function `std::thread::thread<void (*)(int, int, int*), int, int const&, int*, void>(void (*&&)(int, int, int*), int&&, int const&, int*&&)':
main.cpp:(.text._ZNSt6threadC2IPFviiPiEJiRKiS1_EvEEOT_DpOT0_[_ZNSt6threadC5IPFviiPiEJiRKiS1_EvEEOT_DpOT0_]+0x43): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status
Can you help me?
What I have tried:
I've tried give to the thread function "f" or "&f" and else.