Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i create the thread by refering the msdn website..

but i don't know how to pass the variable to it..
Posted
Comments
Sergey Alexandrovich Kryukov 14-Jul-11 3:48am    
What is argument? Some value to be passed before the thread started or when it's already running?
--SA

aimdharma... aren't you tired of downvotes and people asking you to work a little bit your questions?

Take a look at this link[^]... you will see how to do it there...

It seems stupid to me that you son't even bother to search google... At the end you'll be banned and then there won't be any way to get help... can't you see that?

:thumbsdown:
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 14-Jul-11 3:58am    
A 5. Posix is supported by Windows and has a benefits of better portability than Windows-specific solution (I happened to advise, please see).
--SA
Joan M 14-Jul-11 4:14am    
Thank you SAKryukov!
I assume you need to pass some value(s) when the thread is already running which is one of the most general cases of thread synchronization.

Share the variable between threads. Make the variable visible by both threads: the one you send the value and the one using the value. Also, create an instance or Critical Section using InitializeCriticalSection, make it visible by two threads. Create two function: one assigning the value to the variable, another one to read this value. Sandwich the code reading the variable and assignment with EnterCriticalSection and LeaveCriticalSection.

This way you make access to the variable thread-safe. See http://msdn.microsoft.com/en-us/library/ms682530%28v=vs.85%29.aspx[^].

—SA
 
Share this answer
 
v2
Comments
@BangIndia 14-Jul-11 8:16am    
Thanks..
Sergey Alexandrovich Kryukov 14-Jul-11 12:51pm    
If it makes sense for you please formally accept the answer (green button).
If not, please ask your follow-up question.
--SA
Hint: the thread function accepts an argument. See MSDN documentation for a code sample[^].
 
Share this answer
 
Comments
@BangIndia 14-Jul-11 5:03am    
i done it..

How can i pass more than one argument to the thread...
CPallini 14-Jul-11 5:09am    
Pack all the needed arguments in a struct and pass the corrensponding pointer (the linked MSDN code sample already shows how to do it).
@BangIndia 14-Jul-11 5:12am    
yes sir. they shown.. but i want to send one handle and one socket descriptor to the thread .. so only sir
Sergey Alexandrovich Kryukov 14-Jul-11 5:15am    
That is correct of course. My 5. I answered about passing data to running thread just because OP did not answer my question in my comment to the question, so it's not quite clear.
--SA
CPallini 14-Jul-11 5:55am    
I suspect the OP doesn't even realize that 'parameters' are indeed there, i.e. threads share resources.

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