# SDL multithreading and multicore issue

This topic is 2135 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi all, I've been met wit an interesting problem.
First of all, I'd like to say I successfully rolled out my first game framework, which has been my goal for quite some time. Now if I do want to make a game, I can choose a mature engine with no regret.

(Sure there are problems, but as long as it works on my PC, I'm happy )

Anyway, my problem is as follows.
I'm using lua as a script engine. So I exposed a showMsg API to show text on the screen.

So in my script, it runs multiple showMsg commands

They don't seem to be blocking so the text would overlap, which was the reason why I introduced SDL_SemWait and SDL_SemPost

Here's the function that is registered to be called by lua
 int l_showMSG(lua_State *l) { //need a messagebox class //messagebox class will use a list to contain the messages //showMSG should be added to the list #ifndef _DEBUG printf("showMSG::begin\n"); #endif SDL_SemWait(msgLock); char* fontname = (char*) lua_tostring(mainL,-1); lua_pop(mainL,1); wchar_t* txt = (wchar_t *) lua_tostring(mainL,-1); // char* ctxt = (char*) lua_tostring(mainL,-1); std::wstringstream buf; buf << txt; lua_pop(mainL,1); int x = 30; int y = 30; if (lua_gettop(mainL)>0) { y = lua_tonumber(mainL,-1);lua_pop(mainL,1); x = lua_tonumber(mainL,-1);lua_pop(mainL,1); } //wstring msg = buf.str(); //wstring drawmsg = processWide(*msg); #ifndef _DEBUG printf("showMSG::before RenderText\n"); #endif RenderText::drawText(fontname,buf.str(),x,y,true); // delete msg; SDL_SemPost(msgLock); printf("showMSG::done\n"); //delete msg; return 0; } 

This works perfectly fine on my dual core Lenovo, but when I send it to other people. They sometime would see two showMsg calls overlapping.

So my hunch is still that the two lua calls each obtained the lock and both executed the drawtext code.
I'm wondering if it would be due to multicore multi-cache, and if it is so, how would I proceed to fix it?

Thank you

• 15
• 9
• 13
• 41
• 15