1. win32lib et multitasking
- Posted by chadal <francois.chadal at girce.caisse-epargne.fr> Nov 08, 2006
- 826 views
My project uses Euphoria 3.0.1 and win32lib. Recently, i've insert multi-taking functions (task_create, task_schedule, task_suspend and task_yield). Since this update, i've often this kind of error i've never seen before multi-tasking version. Why there is no value ?!? for parms and funcid parameters !?! How can i help to analyse this trouble ? Are there some restrictions of using task_yield in main task ? François Chadal ---------------------- TASK ID 0 initial task ---------------------------- D:\EUPHORIA\Biblio\win32lib\Include\w32dll.ew:283 in procedure w32Proc() A machine-level exception occurred during execution of this statement funcid = <no value> parms = <no value> libfunc = <no value> lFuncDef = <no value> memset = <no value> i = <no value> ... called from D:\EUPHORIA\Biblio\win32lib\Include\Win32Lib.ew:33346 in procedure eventLoop() pData = {} temp = <no value> msg = 10474436 getRC = 1 inc = <no value> el = 1 lTock = 0 ... called from D:\EUPHORIA\Biblio\win32lib\Include\Win32Lib.ew:33553 in procedure WinMain() id = 3 style = 0 lInitFocus = -1 lRtnId = <no value> lEventName = <no value> lInitView = <no value> i = <no value> ... called from D:\EUPHORIA\ose\bin\winOSE.exw:541
global procedure w32Proc(atom funcid, sequence parms) atom libfunc object lFuncDef atom memset memset = 0 for i = 1 to length(parms) do if sequence(parms[i]) then if memset = 0 then memset = w32new_memset() end if parms[i] = w32acquire_mem(memset, parms[i]) end if end for if funcid > kMagicRtnID then funcid -= kMagicRtnID if funcid <= length(vw32Routines) then lFuncDef = vw32Routines[funcid] if sequence(lFuncDef) then if lFuncDef[1] < 0 then lFuncDef[1] = -lFuncDef[1] if vw32Libraries[lFuncDef[1]][1][1] = 0 then vw32Libraries[lFuncDef[1]][1] = linkDLL(vw32Libraries[lFuncDef[1]][2]) end if lFuncDef[1] = vw32Libraries[lFuncDef[1]][1][2] end if lFuncDef = linkProc( lFuncDef[1], -- library lFuncDef[2], -- function name lFuncDef[3] -- param signature ) vw32Routines[funcid] = lFuncDef end if c_proc(lFuncDef, parms) else abortErr(Err_BADFUNCID) end if else if funcid > 0 then c_proc(funcid, parms) -- <--ligne 283 of win32lib\Include\w32dll.ew else abortErr(Err_BADFUNCID) end if end if if memset != 0 then w32release_mem(memset) end if
end procedure
2. Re: win32lib et multitasking
- Posted by Robert Craig <rds at RapidEuphoria.com> Nov 09, 2006
- 750 views
chadal wrote: > My project uses Euphoria 3.0.1 and win32lib. Recently, i've insert > multi-taking > > functions (task_create, task_schedule, task_suspend and task_yield). Since > this > update, i've often this kind of error i've never seen before multi-tasking > version. > > > Why there is no value ?!? for parms and funcid parameters !?! > > How can i help to analyse this trouble ? > > Are there some restrictions of using task_yield in main task ? I don't know what happened, but things can get pretty complicated when you mix multitasking into a GUI program with event-handling. Regards, Rob Craig Rapid Deployment Software http://www.RapidEuphoria.com
3. Re: win32lib et multitasking
- Posted by Ryan W. Johnson <ryanj at fluidae.com> Nov 09, 2006
- 711 views
I was under the impression that libraries like win32lib and wxEuphoria would not work with multitasking, because the winMain() (or equivalent) procedure does not have a task_yield() statement, and therefore will not give up control of the main task to the scheduler. I would that that this statement would have to be added for multitasking to work with these libraries. For example, a win32lib application main loop is basically something like this:
procedure eventLoop(integer id, atom Flag) --SNIP-- -- message loop while Flag != 0 and ActiveEL[el] = 0 and vWinMainState = kStarted do --SNIP-- w32Proc( xTranslateMessage, { msg } ) w32Proc( xDispatchMessage, { msg } ) Flag -= inc --ADD THIS STATEMENT HERE: task_yield() end while --SNIP-- end procedure global procedure WinMain( object id, integer style ) --SNIP-- -- Start processing the message events. eventLoop(0, -1) --SNIP-- end procedure WinMain(winmain, 0)
What I'm saying is, I would think that this main loop in win32lib.ew that handles the win32 messages would need task_yield() added. (Similar circumstance in wxEuphoria, too). Am i correct? ~Ryan W. Johnson Fluid Application Environment http://www.fluidae.com/ [cool quote here, if i ever think of one...]
4. Re: win32lib et multitasking
- Posted by chadal <francois.chadal at girce.caisse-epargne.fr> Nov 09, 2006
- 705 views
Ryan W. Johnson wrote: > > I was under the impression that libraries like win32lib and wxEuphoria would > not work with multitasking, because the winMain() (or equivalent) procedure > does not have a task_yield() statement, and therefore will not give up control > of the main task to the scheduler. I would that that this statement would have > to be added for multitasking to work with these libraries. > > For example, a win32lib application main loop is basically something like > this: > > }}} <eucode> > procedure eventLoop(integer id, atom Flag) > --SNIP-- > -- message loop > while Flag != 0 > and ActiveEL[el] = 0 > and vWinMainState = kStarted do > --SNIP-- > > w32Proc( xTranslateMessage, { msg } ) > w32Proc( xDispatchMessage, { msg } ) > Flag -= inc > --ADD THIS STATEMENT HERE: > task_yield() > > end while > --SNIP-- > end procedure > > global procedure WinMain( object id, integer style ) > --SNIP-- > -- Start processing the message events. > eventLoop(0, -1) > --SNIP-- > end procedure > > WinMain(winmain, 0) > </eucode> {{{ > > What I'm saying is, I would think that this main loop in win32lib.ew that > handles > the win32 messages would need task_yield() added. (Similar circumstance in > wxEuphoria, > too). Am i correct? That's true. I've put two task_yield() statements in two procédures called by setHandlers to work with pre-emptive events from sockets and own winmsg. But for the moment, i've some trouble with win32lib and multitasking. I'm searching for what is wrong in my programs or win32lib or ....and without knowing how to search in depth....that's my first problem. > > ~Ryan W. Johnson > > Fluid Application Environment > <a href="http://www.fluidae.com/">http://www.fluidae.com/</a> > > [cool quote here, if i ever think of one...] regards, François Chadal
5. Re: win32lib et multitasking
- Posted by Jonas Temple <jtemple at yhti.net> Nov 09, 2006
- 713 views
FWIW, I'm working on changes to FROG that will use the new multi-tasking features. Here's one way I found to use the multi-tasking within a win32lib based program. Note that this has not been thoroughly tested yet...
-- Here was the old function call that would execute an SQL statement -- on the host. This is where my program would appear to the user as -- "not responding" -- results = ecadb_execute(sql_system, sql_statement, cpp, -- describe_option, sql) -- I replaced it with this call. "task_sql" is basically the above -- function call. task_schedule(task_create(routine_id("task_sql"), {sql_system,sql_statement,cpp,describe_option,sql}), 1) -- How many tasks are running? task_l = length(task_list()) msg = acquire_mem(0, SIZEOF_MSG) -- Now I drop into a translate/dispatch message loop to keep the -- program responding while I wait for the return results. When the -- task count drops to 1 (main task) I drop out of this loop. -- Process message loop until end of program while w32Func( xGetMessage, { msg, 0, 0, 0 } ) and task_l > 1 do w32Proc( xTranslateMessage, { msg } ) w32Proc( xDispatchMessage, { msg } ) task_yield() task_l = length(task_list()) end while
Now way down in the bowels of the ecadb_execute function I open the DLL with Daniel Kluss' TDLL routines: cwbdb = open_tdll("cwbdb.dll") Then I defined the C function in cwbdb.dll with his define_t_func: -- Old approach -- xcwbDB_Fetch = define_c_func(cwbdb, -- "cwbDB_Fetch", {C_ULONG, C_ULONG}, C_UINT) -- New approach xcwbDB_Fetch = define_t_func(cwbdb, "cwbDB_Fetch", {C_ULONG, C_ULONG}, C_UINT) Then I call the function using his t_func:
global function cwbDB_Fetch(atom request_handle, atom error_handle) -- cwbDB_EURtnCode = c_func(xcwbDB_Fetch, -- {request_handle, error_handle}) cwbDB_EURtnCode = t_func(xcwbDB_Fetch, {request_handle, error_handle}) return {cwbDB_EURtnCode} end function
I realized once I had made these changes that I was going to have to rework a lot of my code to use this approach but frankly it's worth it. All this to say that using tasking with e,xisting win32lib GUI programs is not going to be a trivial matter. Take the time to analyze what changes your program will need. Jonas Temple http://www.yhti.net/~jktemple
6. Re: win32lib et multitasking
- Posted by chadal <francois.chadal at girce.caisse-epargne.fr> Nov 16, 2006
- 707 views
After différents tests to search more in depth, i've activated the trace function with the parameter 3. Results of the ex.err and ctrace.out files are below. But what is the real statement in error ? François Chadal What i see in the ex.err file is : ---------------------- TASK ID 0 initial task ---------------------------- D:\EUPHORIA\Biblio\win32lib\Include\Win32Lib.ew:31798 in function fDoTimer() A machine-level exception occurred during execution of this statement id = <no value> hWnd = <no value> iMsg = <no value> wParam = <no value> lParam = <no value> pReturn = <no value> here the Euphoria code of the fDoTimer() function of in the win32lib program:
---------------------------------------------------- function fDoTimer(integer id, atom hWnd, atom iMsg, atom wParam, atom lParam, atom pReturn) ---------------------------------------------------- VOID = invokeHandler(id, w32HTimer,{wParam} ) return {pReturn} <-- ligne 31798 of win32lib.ew end function
What i see in ctrace.out file just before the end tag is: w32dll.ew:266 if funcid > kMagicRtnID then w32dll.ew:267 funcid -= kMagicRtnID w32dll.ew:268 if funcid <= length(vw32Routines) then w32dll.ew:269 lFuncDef = vw32Routines[funcid] w32dll.ew:271 if sequence(lFuncDef) then w32dll.ew:288 c_proc(lFuncDef, parms) w32dll.ew:182 trace_funcid = funcid w32dll.ew:183 trace_parms = parms w32dll.ew:185 memset = 0 w32dll.ew:186 for i = 1 to length(parms) do w32dll.ew:187 if sequence(parms[i]) then w32dll.ew:193 end for w32dll.ew:187 if sequence(parms[i]) then w32dll.ew:193 end for w32dll.ew:187 if sequence(parms[i]) then w32dll.ew:193 end for w32dll.ew:187 if sequence(parms[i]) then w32dll.ew:193 end for w32dll.ew:194 if funcid > kMagicRtnID then w32dll.ew:195 funcid -= kMagicRtnID w32dll.ew:196 if funcid <= length(vw32Routines) then w32dll.ew:197 lFuncDef = vw32Routines[funcid] w32dll.ew:199 if sequence(lFuncDef) then w32dll.ew:217 lRC = c_func(lFuncDef, parms) w32dll.ew:228 if memset != 0 then w32dll.ew:232 return lRC w32dll.ew:300 trace(0) === THE END ===
7. Re: win32lib et multitasking
- Posted by Chris Bensler <bensler at nt.net> Nov 16, 2006
- 743 views
- Last edited Nov 17, 2006
chadal wrote: > > After différents tests to search more in depth, i've activated the trace > function > with the parameter 3. Results of the ex.err and ctrace.out files are below. > > But what is the real statement in error ? > > François Chadal > > > What i see in the ex.err file is : > > ---------------------- TASK ID 0 initial task ---------------------------- > D:\EUPHORIA\Biblio\win32lib\Include\Win32Lib.ew:31798 in function fDoTimer() > > A machine-level exception occurred during execution of this statement > id = <no value> > hWnd = <no value> > iMsg = <no value> > wParam = <no value> > lParam = <no value> > pReturn = <no value> > > here the Euphoria code of the fDoTimer() function of in the win32lib program: > }}} <eucode> > ---------------------------------------------------- > function fDoTimer(integer id, atom hWnd, atom iMsg, atom wParam, atom lParam, > atom pReturn) > ---------------------------------------------------- > VOID = invokeHandler(id, w32HTimer,{wParam} ) > return {pReturn} <-- ligne 31798 of win32lib.ew > end function > </eucode> {{{ > > What i see in ctrace.out file just before the end tag is: > > w32dll.ew:266 if funcid > kMagicRtnID then > > w32dll.ew:267 funcid -= kMagicRtnID > > w32dll.ew:268 if funcid <= length(vw32Routines) then > > w32dll.ew:269 lFuncDef = vw32Routines[funcid] > > w32dll.ew:271 if sequence(lFuncDef) then > > w32dll.ew:288 c_proc(lFuncDef, parms) > > w32dll.ew:182 trace_funcid = funcid > > w32dll.ew:183 trace_parms = parms > > w32dll.ew:185 memset = 0 > > w32dll.ew:186 for i = 1 to length(parms) do > > w32dll.ew:187 if sequence(parms[i]) then > > w32dll.ew:193 end for > > w32dll.ew:187 if sequence(parms[i]) then > > w32dll.ew:193 end for > > w32dll.ew:187 if sequence(parms[i]) then > > w32dll.ew:193 end for > > w32dll.ew:187 if sequence(parms[i]) then > > w32dll.ew:193 end for > > w32dll.ew:194 if funcid > kMagicRtnID then > > w32dll.ew:195 funcid -= kMagicRtnID > > w32dll.ew:196 if funcid <= length(vw32Routines) then > > w32dll.ew:197 lFuncDef = vw32Routines[funcid] > > w32dll.ew:199 if sequence(lFuncDef) then > > w32dll.ew:217 lRC = c_func(lFuncDef, parms) > > w32dll.ew:228 if memset != 0 then > > w32dll.ew:232 return lRC > > w32dll.ew:300 trace(0) > > > > === THE END === Memory is being corrupted. Try using safe.e to debug memory leaks. Chris Bensler ~ The difference between ordinary and extraordinary is that little extra ~ http://empire.iwireweb.com - Empire for Euphoria
8. Re: win32lib et multitasking
- Posted by chadal <francois.chadal at girce.caisse-epargne.fr> Nov 17, 2006
- 742 views
Thanks for this idea. I will try it. Cordialement, Regards François Chadal