Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SOCKET servsock;

struct sockaddr_in servaddr;

int servlength = sizeof(servaddr);


for(;;)
{

int prxy = accept(servsock, (SOCKADDR*)&servaddr, servlength)

return 0;

}

int newthread = beginthread_(startadress?, 0, NULL); //new thread begins//
// { how do I input parameters to run a process as this new thread?? //


What I have tried:

//I have tried loop, code brackets, passed arg to run a process//
//within that thread// 
//what options do I have to run a process for newly created thread if any?//
beginthread_(threadsrt, 0, thrdprcss)
while(thrdprcss,<=100)
{


int thredprcssfd = someCfunctionapi(int value)

}
Posted
Updated 6-Oct-22 4:11am
v2

The documentation (_beginthread, _beginthreadex | Microsoft Learn[^]) provides sample code (argument passing includes) for both beginthread and beginthreadex.
 
Share this answer
 
With beginthread you first start a new thread.
The thread can then start a new process with one of the exec calls.

beginthread and various exec versions are listed here:
https://learn.microsoft.com/en-us/cpp/c-runtime-library/process-and-environment-control

To start a thread first and then let it start a process doesn't make sense under Windows, because Windows can do that directly.
 
Share this answer
 
At best, this code is a sketch that won't even compile. It has a useless, infinite for loop that returns after invoking accept, the result of which isn't even checked. servsock is declared with no terminating semicolon. I wonder if you're ready to write this kind of code.

That said, the pointer parameter to _beginthread (the recommended version is now _beginthreadex) is used to pass the new thread a pointer to the data that it should use. For example, I have a C++ Thread class, so I use that pointer to provide the thread with a pointer to the object that was created to wrap it. That object would normally be allocated from the heap (malloc or new) so that it will remain allocated until the thread has a chance to access it.
 
Share this answer
 
v2

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