Problem with thread when porting game to windows phone 8

Hi all,
I have a problem when porting game to windows phone 8. In project win32 I use pthread.h but it not working in windows phone 8.
And I find in CCTextureCache of core cocos2d-x, all variable and funtion related to pthread has been put in comment.
eg: in CCTextureCache.cpp
//static pthread_mutex_t s_asyncStructQueueMutex;
//static pthread_mutex_t s_ImageInfoMutex;
or:

//pthread_mutex_lock(&s_asyncStructQueueMutex);

How can i solve this problem?

I have same problem, do you have resolved?

bye

I found wp8 use function in CCPThreadWinRT.h instead of pthread. It seems ok now. Any detail of function that you need?

@chenjc wrote:

I found wp8 use function in CCPThreadWinRT.h instead of pthread. It seems ok now. Any detail of function that you need?

How do you change HttpClient.cpp from pthread to CCPThreadWinRT?

Thanks!!!

You can simply use std::thread, transition is usually pretty straight-forward.

And I recommend C++ REST SDK (casablanca) as a replacement for HTTPClient.

@kuhar wrote:

You can simply use std::thread, transition is usually pretty straight-forward.
but std::thread is not only for c++11? can I set c++11 in visual studio to compile my project and cocos2.2.3?

And I recommend C++ REST SDK (casablanca) as a replacement for HTTPClient.
eh, but I have used HTTPClient in my android and iOS project… :frowning: I want leave the same code… if is possible.

@chenjc wrote:

I found wp8 use function in CCPThreadWinRT.h instead of pthread. It seems ok now. Any detail of function that you need?

I tried include CCPThreadWinRT, but, what do you have inserted instead pthread_create, pthread_exit?

bye and thanks!!

Hi @lordubik, there is a pr about httpclient, libcurl, libwebsocket: https://github.com/cocos2d/cocos2d-x/pull/5098, I added some fix to let it auto-merged and will merged soon. And httpclient works well. Thanks.

but std::thread is not only for c++11? can I set c++11 in visual studio to compile my project and cocos2.2.3?

Yes, it’s c++11 only. There is no switch to choose between c++ standards in VC, c++11 is default and only once since VC10.

@chenjc wrote:

Hi @lordubik, there is a pr about httpclient, libcurl, libwebsocket: https://github.com/cocos2d/cocos2d-x/pull/5098, I added some fix to let it auto-merged and will merged soon. And httpclient works well. Thanks.
I looked the HTTPClient changes and I have applied the changes… but pthread_create is a empty function:

define pthread_create(w,x,y,z) 1
define pthread_detach(x)

I have wrong something? :expressionless:

Thanks for help!!

i have used this code for httpclient wp8

@dungmv wrote:

i have used this code for httpclient wp8
https://github.com/martell/cocos2d-x/blob/curlwinrt/extensions/network/HttpClient.cpp

yes I have taken the same code; but where is pthread_create? because inside CCPThreadWinRT.h there is a empty declaration…
I need httpclient for take a file from a website.

Thanks!

@lordubik, it is not use pthread_create but use create_task to call sendRequest.

see here


I think cocos v2 should create class thread for cocos. so, we can use same code for thread on all platfrom :slight_smile:

@dungmv @lordubik, do you use pthread function in your other game codes frequently? If so, Maybe we need to create implements for pthread function like pthread_create…

yes. AI of game need multi thread

@chenjc wrote:

@dungmv @lordubik, do you use pthread function in your other game codes frequently? If so, Maybe we need to create implements for pthread function like pthread_create…

Hi, thanks for help me.
I don’t use pthread and createtask works well!

Thanks!

@dungmv I replace pthread with std::thread and test ok, using macros.

thank you

Thanks!

Now I have another problem… I have compiled libcurl for release… but I have this errors:

1>lib\multi.c(826): error C2027: use of undefined type ‘pollfd’
1> c:\users\stefano\works\cocos2d-x-2.2.3\cocos2dx\platform\third_party\wp8\libcurl\lib\select.h(90) : see declaration of ‘pollfd’
1>lib\multi.c(845): error C2036: ‘pollfd *’ : unknown size
1>lib\multi.c(845): error C2037: left of ‘fd’ specifies undefined struct/union ‘pollfd’
1>lib\multi.c(846): error C2036: ‘pollfd *’ : unknown size
1>lib\multi.c(846): error C2037: left of ‘events’ specifies undefined struct/union ‘pollfd’
1>lib\multi.c(851): error C2036: ‘pollfd *’ : unknown size
1>lib\multi.c(851): error C2037: left of ‘fd’ specifies undefined struct/union ‘pollfd’
1>lib\multi.c(852): error C2036: ‘pollfd *’ : unknown size
1>lib\multi.c(852): error C2037: left of ‘events’ specifies undefined struct/union ‘pollfd’
1>lib\multi.c(867): error C2036: ‘pollfd *’ : unknown size
1>lib\multi.c(867): error C2037: left of ‘fd’ specifies undefined struct/union ‘pollfd’
1>lib\multi.c(868): error C2036: ‘pollfd *’ : unknown size
1>lib\multi.c(868): error C2037: left of ‘events’ specifies undefined struct/union ‘pollfd’
1>lib\multi.c(870): error C2036: ‘pollfd *’ : unknown size
1>lib\multi.c(870): error C2037: left of ‘events’ specifies undefined struct/union ‘pollfd’
1>lib\multi.c(872): error C2036: ‘pollfd *’ : unknown size
1>lib\multi.c(872): error C2037: left of ‘events’ specifies undefined struct/union ‘pollfd’
1>lib\multi.c(874): error C2036: ‘pollfd *’ : unknown size
1>lib\multi.c(874): error C2037: left of ‘events’ specifies undefined struct/union ‘pollfd’
1>lib\multi.c(890): error C2036: ‘pollfd *’ : unknown size
1>lib\multi.c(890): error C2037: left of ‘revents’ specifies undefined struct/union ‘pollfd’

there is a solution?

Thanks!!!