Discussion:
Recursive critical section in wince 5.0
(too old to reply)
newbie_wince
2010-05-13 16:20:01 UTC
Permalink
Hi,

I have to create a recursive critical section using wince 5.0 API. Here is
the following code that I tried. Is the logic right?








#include "stdafx.h"

#include <stdio.h>
#include <windows.h>

#define MAX 25

int count = 0;


CRITICAL_SECTION cs[MAX];

CRITICAL_SECTION guard;

void os_enter_cs(void);

void os_exit_cs(void);



int _tmain(void)

{


InitializeCriticalSection(&guard);



return 0;

}




void os_enter_cs(void)

{


// guard it



EnterCriticalSection(&guard); // guard

{
count++;
InitializeCriticalSection(&cs[count]);
}

LeaveCriticalSection(&guard); // guard



EnterCriticalSection(&cs[count]);




}






void os_exit_cs(void)

{


EnterCriticalSection(&guard); // guard
{
count--;
LeaveCriticalSection(&cs[count+1]);
DeleteCriticalSection(&cs[count+1]);

}

LeaveCriticalSection(&guard); // guard





}
Paul G. Tobey [eMVP]
2010-05-13 20:03:01 UTC
Permalink
What are you trying to *do*?

Paul T.
Post by newbie_wince
Hi,
I have to create a recursive critical section using wince 5.0 API. Here is
the following code that I tried. Is the logic right?
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
#define MAX 25
int count = 0;
CRITICAL_SECTION cs[MAX];
CRITICAL_SECTION guard;
void os_enter_cs(void);
void os_exit_cs(void);
int _tmain(void)
{
InitializeCriticalSection(&guard);
return 0;
}
void os_enter_cs(void)
{
// guard it
EnterCriticalSection(&guard); // guard
{
count++;
InitializeCriticalSection(&cs[count]);
}
LeaveCriticalSection(&guard); // guard
EnterCriticalSection(&cs[count]);
}
void os_exit_cs(void)
{
EnterCriticalSection(&guard); // guard
{
count--;
LeaveCriticalSection(&cs[count+1]);
DeleteCriticalSection(&cs[count+1]);
}
LeaveCriticalSection(&guard); // guard
}
Bruce Eitman [eMVP]
2010-05-14 13:10:31 UTC
Permalink
As Paul stated, what are you trying to do.

You removed so much code that this doesn't make any sense at all. Your
functions **never** get called. I also cannot find any reason for you to
have an array of critical sections. From what little you show us, you could
do it with a single critical section.
--
Bruce Eitman (eMVP)
Senior Engineer
Bruce.Eitman AT Eurotech DOT com
My BLOG http://geekswithblogs.net/bruceeitman

Eurotech Inc.
www.Eurotech.com
Post by newbie_wince
Hi,
I have to create a recursive critical section using wince 5.0 API. Here is
the following code that I tried. Is the logic right?
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
#define MAX 25
int count = 0;
CRITICAL_SECTION cs[MAX];
CRITICAL_SECTION guard;
void os_enter_cs(void);
void os_exit_cs(void);
int _tmain(void)
{
InitializeCriticalSection(&guard);
return 0;
}
void os_enter_cs(void)
{
// guard it
EnterCriticalSection(&guard); // guard
{
count++;
InitializeCriticalSection(&cs[count]);
}
LeaveCriticalSection(&guard); // guard
EnterCriticalSection(&cs[count]);
}
void os_exit_cs(void)
{
EnterCriticalSection(&guard); // guard
{
count--;
LeaveCriticalSection(&cs[count+1]);
DeleteCriticalSection(&cs[count+1]);
}
LeaveCriticalSection(&guard); // guard
}
newbie_wince
2010-05-17 15:13:02 UTC
Permalink
Hi,
sorry Iam also unclear. I will post in detail later.
Post by Bruce Eitman [eMVP]
As Paul stated, what are you trying to do.
You removed so much code that this doesn't make any sense at all. Your
functions **never** get called. I also cannot find any reason for you to
have an array of critical sections. From what little you show us, you could
do it with a single critical section.
--
Bruce Eitman (eMVP)
Senior Engineer
Bruce.Eitman AT Eurotech DOT com
My BLOG http://geekswithblogs.net/bruceeitman
Eurotech Inc.
www.Eurotech.com
Post by newbie_wince
Hi,
I have to create a recursive critical section using wince 5.0 API. Here is
the following code that I tried. Is the logic right?
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
#define MAX 25
int count = 0;
CRITICAL_SECTION cs[MAX];
CRITICAL_SECTION guard;
void os_enter_cs(void);
void os_exit_cs(void);
int _tmain(void)
{
InitializeCriticalSection(&guard);
return 0;
}
void os_enter_cs(void)
{
// guard it
EnterCriticalSection(&guard); // guard
{
count++;
InitializeCriticalSection(&cs[count]);
}
LeaveCriticalSection(&guard); // guard
EnterCriticalSection(&cs[count]);
}
void os_exit_cs(void)
{
EnterCriticalSection(&guard); // guard
{
count--;
LeaveCriticalSection(&cs[count+1]);
DeleteCriticalSection(&cs[count+1]);
}
LeaveCriticalSection(&guard); // guard
}
.
newbie_wince
2010-05-17 16:31:01 UTC
Permalink
Hi,
I am also unclear. I will update the code and reply later.
Post by Bruce Eitman [eMVP]
As Paul stated, what are you trying to do.
You removed so much code that this doesn't make any sense at all. Your
functions **never** get called. I also cannot find any reason for you to
have an array of critical sections. From what little you show us, you could
do it with a single critical section.
--
Bruce Eitman (eMVP)
Senior Engineer
Bruce.Eitman AT Eurotech DOT com
My BLOG http://geekswithblogs.net/bruceeitman
Eurotech Inc.
www.Eurotech.com
Post by newbie_wince
Hi,
I have to create a recursive critical section using wince 5.0 API. Here is
the following code that I tried. Is the logic right?
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
#define MAX 25
int count = 0;
CRITICAL_SECTION cs[MAX];
CRITICAL_SECTION guard;
void os_enter_cs(void);
void os_exit_cs(void);
int _tmain(void)
{
InitializeCriticalSection(&guard);
return 0;
}
void os_enter_cs(void)
{
// guard it
EnterCriticalSection(&guard); // guard
{
count++;
InitializeCriticalSection(&cs[count]);
}
LeaveCriticalSection(&guard); // guard
EnterCriticalSection(&cs[count]);
}
void os_exit_cs(void)
{
EnterCriticalSection(&guard); // guard
{
count--;
LeaveCriticalSection(&cs[count+1]);
DeleteCriticalSection(&cs[count+1]);
}
LeaveCriticalSection(&guard); // guard
}
.
Loading...