litva
Newbie
Karma: +0/-0
Offline
Posts: 20
278.68 points View InventorySend Money to litva
|
 |
« on: March 14, 2010, 03:34:47 AM » |
|
Hi all.guys, i has had a problem with my code.i am trying to start a new thread. error = pthread_create(&tid[0], NULL, pull_one_url, (void*)urls[0]); but the game is frozen with bus error or without error .what'is it?i am out of my ideas. it's need me to work with internet how in standart browser.image draw and other pictures write in buffer from site.
|
|
|
|
|
Logged
|
|
|
|
|
|
|
|
litva
Newbie
Karma: +0/-0
Offline
Posts: 20
278.68 points View InventorySend Money to litva
|
 |
« Reply #2 on: March 15, 2010, 06:15:24 AM » |
|
/* pthread library for the PSP Copyright (C) 2006 Rafael Cabezas a.k.a. Raf
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ very strange.thank for advise.now i am going to use sceKernelCreateThread."initPriority The initial priority of the thread. Less if higher priority"what is it ?what does thread start early.
|
|
|
|
|
Logged
|
|
|
|
Raphael
Global Moderator
Hero Member
Karma: +230/-10
Offline
Posts: 1431
193700.11 points View InventorySend Money to Raphael
|
 |
« Reply #3 on: March 16, 2010, 01:50:56 AM » |
|
There is no "start early" on PSP, because the threading is coop, not pre-emtive. The question is when do you give your threads time to process, through a sleep/delay in your main thread.
Other than that, it's as is stated, a lower value denotes a higher priority, with 0 the highest. You shouldn't really use anything above priority 12 or 10.
|
|
|
|
|
Logged
|
|
|
|
litva
Newbie
Karma: +0/-0
Offline
Posts: 20
278.68 points View InventorySend Money to litva
|
 |
« Reply #4 on: March 17, 2010, 09:28:33 AM » |
|
on no thid = sceKernelCreateThread("my_thread",(SceKernelThreadEntry)pull_one_url ,10, 0x10000, 0, 0); if(thid >= 0) { sceKernelStartThread(thid, sizeof(urls[0]), (void*)urls[0]); } return bus error.
|
|
|
|
« Last Edit: March 17, 2010, 09:58:03 AM by litva »
|
Logged
|
|
|
|
AlphaDingDong
Combat Muskrat
All-Around Dev
Hero Member
Karma: +32/-3
Offline
Posts: 882
2044.69 points View InventorySend Money to AlphaDingDong
Hey... Are you gonna eat that?
|
 |
« Reply #5 on: March 17, 2010, 08:28:28 PM » |
|
Adapted from a sample I found somewhere a long time ago. I just compiled it and ran it without incident: #include <pspkernel.h> #include <pspctrl.h> #include <pspdebug.h> #include <pspdisplay.h>
PSP_MODULE_INFO("PSP Threading", 0, 1, 1);
int running = 1;
int threadFunction(SceSize argsize, void* arg) { //thread functions must prototype to "int func(Scesize, void*)" while(running) { pspDebugScreenPrintf("This is the thread talking.\n"); sceKernelDelayThread(1); //a sceKernelDelayThread yields time to other threads } sceKernelExitDeleteThread(0); //thread exits and deletes itself return 0; }
int main() { pspDebugScreenInit(); SceCtrlData pad; int thid = sceKernelCreateThread("Talking Thread", threadFunction, 0x10, 0x1000, 0, NULL); //get thread handle - args are ("arbitrary process name", entry point function, thread priority, stack size, attribute flags, SceKernelThreadOptParam*) sceKernelStartThread(thid, 0, NULL); //start the thread - args 2 and 3 are passed into the thread function while(running) { sceCtrlPeekBufferPositive(&pad, 1); if(pad.Buttons & PSP_CTRL_CROSS) {running = 0;} pspDebugScreenPrintf("This is the main thread talking.\n"); sceKernelDelayThread(1); } sceKernelDelayThread(3000000); //pause for a moment so you can see the result sceKernelExitGame(); return 0; }
|
|
|
|
|
Logged
|
|
|
|
litva
Newbie
Karma: +0/-0
Offline
Posts: 20
278.68 points View InventorySend Money to litva
|
 |
« Reply #6 on: March 19, 2010, 08:24:01 AM » |
|
My program stops when there is a start of a new thread, but your example is compiled and starts well
|
|
|
|
« Last Edit: March 20, 2010, 03:37:23 AM by litva »
|
Logged
|
|
|
|
|
|
litva
Newbie
Karma: +0/-0
Offline
Posts: 20
278.68 points View InventorySend Money to litva
|
 |
« Reply #8 on: March 25, 2010, 04:59:18 AM » |
|
my program is frozen when thread starts!!!
|
|
|
|
« Last Edit: March 25, 2010, 05:01:00 AM by litva »
|
Logged
|
|
|
|
Raphael
Global Moderator
Hero Member
Karma: +230/-10
Offline
Posts: 1431
193700.11 points View InventorySend Money to Raphael
|
 |
« Reply #9 on: March 25, 2010, 07:00:59 AM » |
|
can't answer why, without showing us the exact code.
|
|
|
|
|
Logged
|
|
|
|
litva
Newbie
Karma: +0/-0
Offline
Posts: 20
278.68 points View InventorySend Money to litva
|
 |
« Reply #10 on: March 25, 2010, 09:29:33 AM » |
|
static int pull_one_url(char *url) { curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writer);
//указываем куда записывать принимаемые данные curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer); curl_easy_perform(curl);
return 1; } int threadFunction(SceSize argsize, void* arg){ pull_one_url(urls[0]); sceKernelExitDeleteThread(0); return 1; } ... thid1 = sceKernelCreateThread("Talking Thread", threadFunction, 0x05, 0x1000, 0, 0); sceKernelStartThread(thid1, 0, NULL); ...
|
|
|
|
|
Logged
|
|
|
|
Raphael
Global Moderator
Hero Member
Karma: +230/-10
Offline
Posts: 1431
193700.11 points View InventorySend Money to Raphael
|
 |
« Reply #11 on: March 25, 2010, 10:16:54 AM » |
|
1. use code tags when posting code int threadFunction(SceSize argsize, void* arg){ pull_one_url(urls[0]); sceKernelExitDeleteThread(0); return 1; }
2. Where/how is the urls array declared? 3. Why do you start a thread, that in turn just calls a single function and returns? Since the function itself is blocking and the psp has a coop threading model, you actually gain nothing from starting it in a thread, other than possibly delaying the function call a little bit, depending on what you main thread does after creating this thread. thid1 = sceKernelCreateThread("Talking Thread", threadFunction, 0x05, 0x1000, 0, 0);
0x5 is pretty high priority and shouldn't be used unless you know what you do. Start with something like 0x18 and slowly decrease it, if you feel the thread isn't "responsive" enough.
|
|
|
|
|
Logged
|
|
|
|
litva
Newbie
Karma: +0/-0
Offline
Posts: 20
278.68 points View InventorySend Money to litva
|
 |
« Reply #12 on: March 26, 2010, 04:50:36 AM » |
|
const char * const urls[4]= { "http://ourgame.orgfree.com/store/", "ftp://cool.haxx.se/", "http://www.contactor.se/", "www.haxx.se" }; thread starts and returns bus error,This function stops thread and waits while the page is loading .
|
|
|
|
« Last Edit: March 27, 2010, 11:33:12 PM by litva »
|
Logged
|
|
|
|
|