semaphores

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
daaa57150
Posts: 28
Joined: Fri Nov 17, 2006 10:35 pm

semaphores

Post by daaa57150 »

Hi,

I have searched a lot about this and I thought I've found the proper way to have a mutex but it seems it's not the case, my PSP freezes. can please someone tell me if I do this correctly:

I have an object that will handle a thread internally let's call it ObjWithThread. This ObjWithThread contains a std::list that needs to be protected with a mutex, as the thread it launches modifies it.
So, I made this ObjWithThread have a semaphore member m_semaid like this:

Code: Select all

m_semaid = sceKernelCreateSema("OWTSema", 0, 1, 1, 0);
and 2 functions to lock/unlock the object, that I call before/after reading from the list from outside the ObjWithThread:

Code: Select all

void ObjWithThread::lock()
{
	sceKernelWaitSema(m_semaid, 1, 0);
}

void ObjWithThread::unlock()
{
	sceKernelSignalSema(m_semaid, 1);
}
the inner thread is created like this:

Code: Select all

m_threadId = sceKernelCreateThread("OWTThread", OWTfunction, 0x11, 0xFA0, PSP_THREAD_ATTR_USER|PSP_THREAD_ATTR_VFPU, NULL);
and launched like this:

Code: Select all

sceKernelStartThread(owt->m_threadId, sizeof(owt), &owt); //owt is a pointer to the ObjectWithThread itself
and before the thread tries to write to the list, I call the lock function, and after the writing is finished, I call the unlock function and sceKernelDelayThread(500) because it's in an infinite loop:

Code: Select all

void ObjWithThread::OWTfunction(SceSize args, void *argp)
{
	ObjWithThread *_this = *((ObjWithThread**) argp);
	while(true)
	{
		_this->lock();
		//here I modify the std::list
		_this->unlock();
		sceKernelDelayThread(500);
	}
}
what is wrong in there? The PSP freezes if I try to access the std::list from outside the ObjWithThread, and works correctly if I don't touch it. This means the list is not protected with the mutex, and I can't figure out why!

Help...
daaa57150
Posts: 28
Joined: Fri Nov 17, 2006 10:35 pm

Post by daaa57150 »

I got help on QJ, it works now if someone is interested:
http://forums.qj.net/showthread.php?p=2 ... ost2064106
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

First, we already knew how the use semaphores - you'll find examples all over this forum. That's why no one answered your thread - you hadn't bothered to search, so we didn't bother to answer.

Second, QJ.net sucks. Post count is the almighty factor in how you're treated, and the idiots who do nothing but post inane "me too" posts to increase their count run the forum. I rarely went over there before, and after an incident a couple days ago, I'm never going back and encourage everyone else to avoid that forum as well.

Just as an idea of how stupid they are over at QJ.net - someone recently took an OLD copy of the REALLY OLD 0.5 version of PSPDoom, repacked it with eLoader, and had QJ.net put it out as a "brand new" 3.xx version of Doom. Never mind the fact that PSPDoom was updated for 3.xx more than six months ago. Never mind the fact that my own version of Doom was released about six months ago. It's new! It keeps noobies coming to the site! They don't even allow comments on releases, so you can't warn people to avoid stuff like that. There were almost 3000 downloads of it in a few days by people who were going to be VERY disappointed. That describes how I feel about QJ.net in general - VERY disappointed.
Pirata Nervo
Posts: 409
Joined: Tue Oct 09, 2007 4:22 am

Post by Pirata Nervo »

That sucks J.F. :(
Image
Upgrade your PSP
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

They've got a big database of homebrew... that's about the only plus they have - as long as you watch out for repackaged garbage like I mentioned above.
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

Thats because the blog is managed by different people who don't know anything about the PSP, not the forum mods/staff.
daaa57150
Posts: 28
Joined: Fri Nov 17, 2006 10:35 pm

Post by daaa57150 »

J.F. wrote:First, we already knew how the use semaphores - you'll find examples all over this forum. That's why no one answered your thread - you hadn't bothered to search, so we didn't bother to answer.
The fact is, I have bothered to search, I found how to use semaphores here on ps2dev, but my PSP was still freezing, and at the time of writing I didn't know why.
If you had bothered to help me, like they did on QJ, you might have spotted that the problem was a stack problem, and just saying "your semaphore use is correct" would have spare me a bunch of time. But I'm glad you know how to use semaphores yourself.
J.F. wrote:Second, QJ.net sucks. Post count is the almighty factor in how you're treated, and the idiots who do nothing but post inane "me too" posts to increase their count run the forum. I rarely went over there before, and after an incident a couple days ago, I'm never going back and encourage everyone else to avoid that forum as well.
I encourage people to search for help at QJ, there are a lot more chances to get an answer there. Sure, the quality in the answers is usually a lot lower than here at ps2dev, but usually here 1 of 2 subject I make don't get an answer at all.
J.F. wrote:Just as an idea of how stupid they are over at QJ.net - someone recently took an OLD copy of the REALLY OLD 0.5 version of PSPDoom, repacked it with eLoader, and had QJ.net put it out as a "brand new" 3.xx version of Doom. Never mind the fact that PSPDoom was updated for 3.xx more than six months ago. Never mind the fact that my own version of Doom was released about six months ago. It's new! It keeps noobies coming to the site! They don't even allow comments on releases, so you can't warn people to avoid stuff like that. There were almost 3000 downloads of it in a few days by people who were going to be VERY disappointed. That describes how I feel about QJ.net in general - VERY disappointed.
Well, there are stupid people at QJ, especially the newsers but there are also nice and skilled people that want to help on the forum.
User avatar
jean
Posts: 489
Joined: Sat Jan 05, 2008 2:44 am

Post by jean »

We all know that people over here are often rough (to say it nice), J.F. in the first line. But you have to notice that the greatest part of active developers on ps2dev are professionals, and most of them are REALLY sick with children playing to "the greatest hacker". That's why Tyranid always asks what one is trying to do before answering to a question, i guess. I don't give a shit about QJ.net, and if you like it, then use it. Similarly, if you don't like ps2dev then don't use it. We can't spend our entire life teaching to dummies how to code an "hello world".
daaa57150
Posts: 28
Joined: Fri Nov 17, 2006 10:35 pm

Post by daaa57150 »

jean wrote:We all know that people over here are often rough (to say it nice), J.F. in the first line. But you have to notice that the greatest part of active developers on ps2dev are professionals, and most of them are REALLY sick with children playing to "the greatest hacker". That's why Tyranid always asks what one is trying to do before answering to a question, i guess. I don't give a shit about QJ.net, and if you like it, then use it. Similarly, if you don't like ps2dev then don't use it. We can't spend our entire life teaching to dummies how to code an "hello world".
I like ps2dev because as you said, many people here are professional and when I get a answer other than "use the search button" and the likes, it usually is really helpful. And also I can get past answers like I received just here, I know my post was legitimate. And I like QJ because I know I will almost always get an answer, even if the chance of getting a professional answer is (a lot) thinner. That's why I post on ps2dev when I think my problem is difficult, and then if I don't get an answer I put it on QJ. And this time, well, QJ was better, yes it happens. And I'm not coding a Hello World by the way (but you know that).
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

daaa57150 wrote: If you had bothered to help me, like they did on QJ, you might have spotted that the problem was a stack problem
Oh yes, because the little snippets you posted in the opening post would have allowed anyone to see that. :headdesk:

Lord save us from noobies who can't tell a bad semaphore from a stack overflow!! Well, you claim to have learned how to search - now you just need to learn how to debug!
daaa57150
Posts: 28
Joined: Fri Nov 17, 2006 10:35 pm

Post by daaa57150 »

J.F. wrote:Oh yes, because the little snippets you posted in the opening post would have allowed anyone to see that. :headdesk:
I don't think so but noone asked me more details. Noone said it couldn't be because of the semaphores. with some discussion things go forward you know.
J.F. wrote:Lord save us from noobies who can't tell a bad semaphore from a stack overflow!! Well, you claim to have learned how to search - now you just need to learn how to debug!
Yes I agree I need to learn to better debug that sort of things. And I made a progress thanks to Insert_Witty_Name on QJ who gave me some good advice. Certainly things that many people here on ps2dev know, but don't bother teach the others.

I don't know why you have this attitude really. You like being self sufficient and mean to those who want to learn? I think it's really the opposite of what I thought this site was all about. Seriously, I were a mod here I would just warn you.
Pirata Nervo
Posts: 409
Joined: Tue Oct 09, 2007 4:22 am

Post by Pirata Nervo »

lol if a mod warns someone for don't telling the others what to do I guess everybody will leave this forum.
Image
Upgrade your PSP
daaa57150
Posts: 28
Joined: Fri Nov 17, 2006 10:35 pm

Post by daaa57150 »

Pirata Nervo wrote:lol if a mod warns someone for don't telling the others what to do I guess everybody will leave this forum.
That's not what I meant, I meant for that attitude of being so scornful.
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Sorry, but we get in that kind of mood when people ask about simple things that developers should already know... like how to debug. We aren't here to hold people's hands. There are plenty of other sites that specialize in beginner programming. When you come here, you should already be proficient at programming. We cut folks slack when they do things like read the old threads and search before asking, otherwise, we cut something else. ;)

And if you think I'm bad, you haven't been here long. I just tend to be condescending. If you want to see some REAL abuse, go check out the Hall of Shame. :)
daaa57150
Posts: 28
Joined: Fri Nov 17, 2006 10:35 pm

Post by daaa57150 »

J.F. wrote:Sorry, but we get in that kind of mood when people ask about simple things that developers should already know... like how to debug. We aren't here to hold people's hands.
You are not here to help? ok good to know, just don't bash freely on people that are sometimes a little bit more noobish than you, not everyone is excelling magnificiently everywhere like you.
J.F. wrote:There are plenty of other sites that specialize in beginner programming. When you come here, you should already be proficient at programming.
I did not think that was a beginner problem I had, and I'm proficient in many aspects of programming if there is a slight hypothetic chance that you want to know.
J.F. wrote:We cut folks slack when they do things like read the old threads and search before asking, otherwise, we cut something else. ;)
What makes you think I haven't? I have done it and as you should have understood now (you are so great so I'm sure you have), I made it correctly, the problem was somewhere else.
J.F. wrote:And if you think I'm bad, you haven't been here long. I just tend to be condescending. If you want to see some REAL abuse, go check out the Hall of Shame. :)
Maybe I will, but not beeing as bad as others don't makes you a good person. But I'm warned now, thank you.
Cpasjuste
Posts: 214
Joined: Sun May 29, 2005 8:28 am

Post by Cpasjuste »

With all your unusefull comment's JF the ps2dev psp forum are almost like qj.net forum now ... sorry for this but it's not the first time i think you are a bit aggresive. If you hav'nt replied to this thread, it would be done.
User avatar
jean
Posts: 489
Joined: Sat Jan 05, 2008 2:44 am

Post by jean »

Pleeeeeeeeeeeeeeease stop it! We all know that an half of JF's posts are querelles, but i have to admit that he's right at least a third of the times...i undertand him because to know the things i know today, i'm studing (more or less) for 20 years; so seeing people claiming they're proficient in programming while they demonstrate they know NOTHING is a little frustrating. Moreover, seeing people being unkind because experts HAVE to help others make me really sick! We don't _have_ to do NOTHING! And if we encourage children copying code sunday mornings, we'll se the scene DIE SHORTLY!!!! People around here should know everything about computer programming and should ask only PSP related questions as a guideline. Then if someone uses the forum to kindly chat about nerd's topics it's not an issue for me as long as i don't find evey day two or three posts on "Installing toolchain" or "converting numbers to strings, PLEASE HELP!!!". Life is so difficult, sometimes..............
daaa57150
Posts: 28
Joined: Fri Nov 17, 2006 10:35 pm

Post by daaa57150 »

Sorry to continue this but I feel quite insulted without a proper reason so I wont run dragging my tail behind me in shame.
jean wrote:to know the things i know today, i'm studing (more or less) for 20 years; so seeing people claiming they're proficient in programming while they demonstrate they know NOTHING is a little frustrating.
I'm studying / working in programming for 8 years so I don't think I know nothing, and I don't think I demonstrated that.
jean wrote:Moreover, seeing people being unkind because experts HAVE to help others make me really sick! We don't _have_ to do NOTHING!
I wasn't unkind, or at least not intentionally (I'm sorry if I did, I'm not a native english speaker so sometimes I don't choose my words correctly). I don't think experts HAVE to help me: I asked, nobody answered, I found answers somewhere else, gave a link for those interested and then got an aggressive answer. If someone is unkind here, that's not me.
jean wrote:And if we encourage children copying code sunday mornings, we'll se the scene DIE SHORTLY!!!!
Keeping the knowledge between yourselves too, because once you skilled people will loose interest in the PSP, the scene will be dead. I think I was somewhere in the middle, asking to go further.
jean wrote:People around here should know everything about computer programming and should ask only PSP related questions as a guideline. Then if someone uses the forum to kindly chat about nerd's topics it's not an issue for me as long as i don't find evey day two or three posts on "Installing toolchain" or "converting numbers to strings, PLEASE HELP!!!"..
Clearly, semaphores and thread problems are at the same level than number to string conversion. I think I have still a long way to go then..
hlide
Posts: 739
Joined: Sun Sep 10, 2006 2:31 am

Post by hlide »

daaa57150, it's okay. You just happen to fall here the wrong moment (Ne0h episode, noobish questions, psptoolchain install trouble, etc.).
Last edited by hlide on Sat Jun 21, 2008 1:13 am, edited 1 time in total.
Pirata Nervo
Posts: 409
Joined: Tue Oct 09, 2007 4:22 am

Post by Pirata Nervo »

Close this thread >.<
Image
Upgrade your PSP
daaa57150
Posts: 28
Joined: Fri Nov 17, 2006 10:35 pm

Post by daaa57150 »

hlide wrote:daaa57150, it's okay. It just happens you fall here the wrong moment (Ne0h episode, noobish questions, psptoolchain install trouble, etc.).
Ok, I understand.
Last edited by daaa57150 on Sat Jun 21, 2008 5:16 pm, edited 3 times in total.
Pirata Nervo
Posts: 409
Joined: Tue Oct 09, 2007 4:22 am

Post by Pirata Nervo »

Image
Upgrade your PSP
User avatar
jean
Posts: 489
Joined: Sat Jan 05, 2008 2:44 am

Post by jean »

daaa57150, it's okay. You just happen to fall here the wrong moment (Ne0h episode, noobish questions, psptoolchain install trouble, etc.).
Yes...he's right. Never thougt semaphores and parallelization problems are on the same level of string formatting, and the post was not aimed only at you (or at least it wasn't a reply to your question). I just take position when you incentive others to go on other forums because this isn't noob-friendly...nothing personal
daaa57150
Posts: 28
Joined: Fri Nov 17, 2006 10:35 pm

Post by daaa57150 »

jean wrote:Yes...he's right. Never thougt semaphores and parallelization problems are on the same level of string formatting, and the post was not aimed only at you (or at least it wasn't a reply to your question). I just take position when you incentive others to go on other forums because this isn't noob-friendly...nothing personal
Ok no big deal then, and I'm sorry about the incitement. But hey, if a bunch of noobs follow my advice and go somewhere else, it's a good thing isn't it :) ?
Post Reply