• Welcome to OS2World OLD-STATIC-BACKUP Forum.
 

News:

This is an old OS2World backup forum for reference only. IT IS READ ONLY!!!

If you need help with OS/2 - eComStation visit http://www.os2world.com/forum

Main Menu

rexx dll + threads + semaphores

Started by jep, 2007.07.12, 14:14:51

Previous topic - Next topic

jep

Hello,
I've tried to write a rexx dll and managed to include some neat features, eject/load CD/DVD, calculate filesizes above 2Gb, list files to rexxqueue, stem and stdout to allow flexible use and earlier output in multithreaded apps (rexxqueue + threads provided by e.g. DrDialog through Start). ;D

I've never managed to get a working example using threads in the C/C++ code to come close to working properly for me though.

Would you please correct the following example so that it can work? ???

The problems (as seem to me) is that it can only return to rxMergeMove if i include a
cout << "Something";
on the first lines of the function(thread) MergeMove, but it (the calling rexx code) end execution before the return from DosWaitEventSem

Compiler: OpenWatcom v1.6

/** MergeMove **/

/** Code removed to improve readability **/
/* Please see attached file (RXTNSION.zip) for the current status of the project */

********22 July, 2007*********
download file from http://www.xn--lrka-loa.com/RXTNSION.zip, for more info see included files... unzip to C:\Temp\RxTnsion so you don't have to change paths in the project. Just open and "make".
=====================

mvh
//Jan-Erik

mobybrick

Hi,

Don't really know a lot about thread programming, but as a suggestion should the thread creation line be:

   rc = DosCreateThread( &tid, (PFNTHREAD)MergeMove, ( ULONG ) &rxMergeMoveP, CREATE_READY | STACK_SPARSE, 8192L );


It might also be worth testing, using cout or the debugger, to make sure the handle to the semaphore is being correctly maintained as your program runs. Use perhaps cout to dump the value of plist->handle and rxMergeMoveP.sHandle to screen as the program runs.

Sorry can't be more help at the moment. Post more code if you can (i.e. calling rexx function).

Regards,
Moby

Radek

(a) DosExit(EXIT_PROCESS,rc) quits the whole app, not only the current thread. Comment it out (you can simply return from the thread main, this will quit the thread for you) or replace it by DosExit(EXIT_THREAD,rc).
(b) Do not call DosCreateThread in C/C++ code yourself. Use _beginthread every time you can. That's because the standard library procedures need a multithreading environment in a multithreading app. _beginthread creates the environment for a new thread and then it calls DosCreateThread.

mobybrick

I think Radek's suggestions are somewhat better than mine  ;) I was trying to see why the cout statement in MergeMove would make any difference - still can't see why.

The documentation that I have here doesn't show _beginthread use, but I know there was a press item about uninitialized threads in some common apps...

Regards,
Moby

jep

#4
Please see attached .zip-file


****For those of you that's not logged in****July 22, 2007****
download the .zip-file from my homepage http://www.xn--lrka-loa.com/RXTNSION.zip RXTnsion.zip that contain the complete project, suitable to build right away using OpenWatcom.

Unzip to C:\Temp\RxTnsion so you don't have to change paths in the project,just open and "make all".
============

Note:
rxtension_cpp_newer.wrk was the "clean" version that I used to create the dll before I added code to test threads.

var.hpp and var.cpp contain the super-duper-class that can do almost everything for me, inspired by rexx... just in case you wonder why.

OpenWatcom v1.6 project

mvh / Wkr / MfG
//Jan-Erik

jep

I forgot to mention that the intention with the function rxMergeMove is to retrieve name of files so that the other thread can move the files. It should copy files even if the target folder contain folders with equal names as the source folders (compare to options provided by wps copy now).

If you come up with a better solution... please do tell me.

While you're at it looking for a solution to help me out, please do tell me how to add IPC to the code too, as the threads need it to exchange filenames  ;)

mvh / MfG / Wkr
//Jan-Erik

Andi

Quote
I've never managed to get a working example using threads in the C/C++ code to come close to working properly for me though.
Did http://www.edm2.com/0106/threadspm.html not work for you?

jep

Not quite what I've searched for, as it focus on PM programming, but I'll use that to guide me futher... thank you Andi!

You wouldn't have some link to an IPC example, would you?

mvh /Wkr / MfG
//Jan-Erik

jep

I still can't make it work, it just exit before early in the thread function and then also in the main function.

Please provide me with more info. perhaps an example or a corrected file/project?!

mvh / Wkr / MfG
//Jan-Erik