Discussion:
SSL HttpOpenRequest/createThread works on SP fails on PPC!!
(too old to reply)
Fred
2007-11-15 01:02:14 UTC
Permalink
Hi,

I am trying to connect to a SSL (https) using the Device Emulator (v2) and
WM5.

It works fine on the Smartphone, yet fails on the Pocket PC (DE 2) when I
create more that 16 threads!!!!.

(In the actual program I create a threadpool on startup)

I have cobbled together a quick hack (below) to illustrate the problem.

To summarise I create the threads then try to connect to the HTTPS
a. no threads - works on both PPC and SP.
b. < 16 Threads - works on SP and PPC.
c. >=16 Threads - works on SP fails and PPC.

Surely I'm missing something simple, some environment variable or something
on the PPC emulator.

I am dazed and confused.

Any help appreciated

int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
CThreadPoolSimple *pWTPool =new CThreadPoolSimple();//fails
testSSL();//Fails!!!!!!!!
.
.
.

###
//#define MAX_THREADS 15 //works
#define MAX_THREADS 16 //faisl on PPC

CThreadPoolSimple()
{
PMYDATA pData;
DWORD dwThreadId[MAX_THREADS];
HANDLE hThread[MAX_THREADS];
int i;

// Create MAX_THREADS worker threads.

int j=MAX_THREADS;
for( i=0; i<MAX_THREADS; i++ )
{
// Allocate memory for thread data.

pData = (PMYDATA)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
sizeof(MYDATA));

if( pData == NULL )
ExitProcess(2);

// Generate unique data for each thread.

pData->val1 = i;
pData->val2 = i+100;

hThread[i] = CreateThread(
NULL, // default security attributes
0, // use default stack size
ThreadProc1, // thread function
pData, // argument to thread function
CREATE_SUSPENDED, // use default creation flags
&dwThreadId[i]); // returns the thread identifier


}


}





###
int testSSL()
{

//Hack Stuff

DWORD a=0;
HINTERNET hSession,hDownload,hRequest;
if((hSession = InternetOpen(_T("MFFS"), INTERNET_OPEN_TYPE_DIRECT, NULL,
NULL, 0)) == NULL){return 0;
}

if((hDownload = InternetConnect(hSession, _T("login.yahoo.com"),
INTERNET_DEFAULT_HTTPS_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0)) ==
NULL){
return 0;

}



if((hRequest = HttpOpenRequest(hDownload, _T("POST"),
_T("https://login.yahoo.com/config/login?"), NULL, NULL, NULL,
INTERNET_FLAG_SECURE, 0)) == NULL){
a=GetLastError();
// Error 1359 is ERROR_INTERNAL_ERROR
return 0;
}

return(1);

}
Fred
2007-11-15 12:24:47 UTC
Permalink
Post by Fred
Hi,
Surely I'm missing something simple, some environment variable or something
on the PPC emulator.
On further investigation I has come to the conclusion it is a system
resources issue which I need to investigate further.
Vladimir Scherbina
2007-11-28 14:42:31 UTC
Permalink
Seems like the problem is trivial. You create too much threads.
--
Vladimir
Post by Fred
Hi,
I am trying to connect to a SSL (https) using the Device Emulator (v2) and
WM5.
It works fine on the Smartphone, yet fails on the Pocket PC (DE 2) when I
create more that 16 threads!!!!.
(In the actual program I create a threadpool on startup)
I have cobbled together a quick hack (below) to illustrate the problem.
To summarise I create the threads then try to connect to the HTTPS
a. no threads - works on both PPC and SP.
b. < 16 Threads - works on SP and PPC.
c. >=16 Threads - works on SP fails and PPC.
Surely I'm missing something simple, some environment variable or something
on the PPC emulator.
I am dazed and confused.
Any help appreciated
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
CThreadPoolSimple *pWTPool =new CThreadPoolSimple();//fails
testSSL();//Fails!!!!!!!!
.
.
.
###
//#define MAX_THREADS 15 //works
#define MAX_THREADS 16 //faisl on PPC
CThreadPoolSimple()
{
PMYDATA pData;
DWORD dwThreadId[MAX_THREADS];
HANDLE hThread[MAX_THREADS];
int i;
// Create MAX_THREADS worker threads.
int j=MAX_THREADS;
for( i=0; i<MAX_THREADS; i++ )
{
// Allocate memory for thread data.
pData = (PMYDATA)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
sizeof(MYDATA));
if( pData == NULL )
ExitProcess(2);
// Generate unique data for each thread.
pData->val1 = i;
pData->val2 = i+100;
hThread[i] = CreateThread(
NULL, // default security attributes
0, // use default stack size
ThreadProc1, // thread function
pData, // argument to thread function
CREATE_SUSPENDED, // use default creation flags
&dwThreadId[i]); // returns the thread identifier
}
}
###
int testSSL()
{
//Hack Stuff
DWORD a=0;
HINTERNET hSession,hDownload,hRequest;
if((hSession = InternetOpen(_T("MFFS"), INTERNET_OPEN_TYPE_DIRECT, NULL,
NULL, 0)) == NULL){return 0;
}
if((hDownload = InternetConnect(hSession, _T("login.yahoo.com"),
INTERNET_DEFAULT_HTTPS_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0)) ==
NULL){
return 0;
}
if((hRequest = HttpOpenRequest(hDownload, _T("POST"),
_T("https://login.yahoo.com/config/login?"), NULL, NULL, NULL,
INTERNET_FLAG_SECURE, 0)) == NULL){
a=GetLastError();
// Error 1359 is ERROR_INTERNAL_ERROR
return 0;
}
return(1);
}
v***@gmail.com
2007-12-21 09:40:40 UTC
Permalink
This is already answered i guess.. but remember a thread needs it's
own stack etc... so generating a new thread will impose serious
reservations of stack aswell as heap.. By default, a new thread would
reserve about 1 MB of memory.. so if these threads are running in
parallell, you will suffer a memory problem.. I guess you could use
fibers instead, but i don't think there is much of a gain in resource-
usage..

Sander
Volodymyr Shcherbyna
2007-12-21 10:06:13 UTC
Permalink
Not only stack is the issue.

Actually, each thread has it's contex (CONTEXT strucutre), it's thread
envionment block (TEB structure), in kernel mode, thread is represented as
an KTHREAD object.
--
Volodymyr
Post by v***@gmail.com
This is already answered i guess.. but remember a thread needs it's
own stack etc... so generating a new thread will impose serious
reservations of stack aswell as heap.. By default, a new thread would
reserve about 1 MB of memory.. so if these threads are running in
parallell, you will suffer a memory problem.. I guess you could use
fibers instead, but i don't think there is much of a gain in resource-
usage..
Sander
Loading...