Click here to Skip to main content
15,887,328 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
cv::VideoCapture a;
	cv::VideoCapture b;
	cv::VideoCapture c;
	cv::VideoCapture d;
	a.open("traffic1.mp4");
	b.open("traffic2.mp4");
	c.open("traffic3.mp4");
	d.open("traffic4.mp4");
	std::thread t1 (traffic,a,"a");
	std::thread t2 (traffic, b, "b");
	std::thread t3(traffic, c, "c");
	std::thread t4(traffic, d, "d");
	t1.join();
	t2.join();
	t3.join();
	t4.join();

here in function traffic() there is a integer value how can i access it what is the syntax

What I have tried:

i did't get any syntax for this
Posted
Updated 13-Mar-17 0:39am
Comments
Jochen Arndt 13-Mar-17 6:25am    
How should we know?

You did not show us the traffic() function and the posted code did not contain any integer variable.

1 solution

For use in other functions you must declare a global variable. You can use a normal int outside the traffic function.

But I would call it a major flaw that you have different threads accessing the same variable if the variable isnt constant for all threads .

It is not clear which thread wins the race for access. So it is better to write an getInteger() and setInteger() function with some syncronization code.

Please read the article C++11 threads, locks and condition variables for better understanding the pitfalls and solutions.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900