Author Topic: rexx dll + threads + semaphores  (Read 4705 times)

jep

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 421
    • View Profile
rexx dll + threads + semaphores
« on: 2007.07.12, 13:14:51 »
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
« Last Edit: 2007.07.22, 12:02:48 by jep »

mobybrick

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Re: rexx dll + threads + semaphores
« Reply #1 on: 2007.07.13, 13:55:34 »
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

  • Full Member
  • ***
  • Posts: 201
    • View Profile
Re: rexx dll + threads + semaphores
« Reply #2 on: 2007.07.13, 14:38:23 »
(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

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Re: rexx dll + threads + semaphores
« Reply #3 on: 2007.07.13, 15:09:22 »
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

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 421
    • View Profile
Re: rexx dll + threads + semaphores
« Reply #4 on: 2007.07.14, 02:00:29 »
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
« Last Edit: 2007.07.22, 11:59:59 by jep »

jep

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 421
    • View Profile
Re: rexx dll + threads + semaphores
« Reply #5 on: 2007.07.31, 21:09:08 »
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

  • Sr. Member
  • ****
  • Posts: 264
    • View Profile
Re: rexx dll + threads + semaphores
« Reply #6 on: 2007.08.01, 13:11:49 »
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

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 421
    • View Profile
Re: rexx dll + threads + semaphores
« Reply #7 on: 2007.08.01, 19:08:51 »
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

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 421
    • View Profile
Re: rexx dll + threads + semaphores
« Reply #8 on: 2007.08.07, 09:01:01 »
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