Jump to content


Photo

FSUIPC with threads (it's possible?)

FSUIPC threads

  • Please log in to reply
11 replies to this topic

#1 Leonardo Freschi

Leonardo Freschi

    Newbie

  • new Members
  • Pip
  • 1 posts

Posted 10 August 2012 - 06:07 AM

Hello,

I'm programming with FSUIPC dll, and I'd to use threads, but I'm getting some troubles to do that.
My question is if it's possible to use threads to read many variables on FS in the same time using the function FSUIPC_Read, passing in parameter dwResult, without use waits in any thread. The dwResult variable appears to be overwrite in each acess.

Ty,
Regard,

Leonardo Freschi.
  • 0

#2 Pete Dowson

Pete Dowson

    Advanced Member

  • Moderators
  • 27,355 posts
  • LocationNear Stoke-on-Trent, UK

Posted 10 August 2012 - 09:09 AM

I'm programming with FSUIPC dll, and I'd to use threads, but I'm getting some troubles to do that.
My question is if it's possible to use threads to read many variables on FS in the same time using the function FSUIPC_Read, passing in parameter dwResult, without use waits in any thread. The dwResult variable appears to be overwrite in each acess.


The interface from an application process into FSUIPC doesn't care about threads, but when you open the link (FSUIPC_Open) only one shared memory area is used for all of the exchanges. So you either must keep all the Reads and Writes in one thread, or synchronise them so there is no possibility of an overlap.

The best thing to do is have a thread running which does all the FSUIPC_Read and FSUIPC_Write actions, with one FSUIPC_Process call per cycle. There's no point in having multiple threads reading and writing separately. Only the Process call actually does anything -- all the Reads and Writes are doing is building the request list in the shared memory area.

Regards
Pete
  • 0

#3 mgh

mgh

    Advanced Member

  • Members
  • PipPipPip
  • 68 posts
  • LocationUK

Posted 10 August 2012 - 11:56 AM

Is it possible to have multiple instances of FSUIPC executing at the same time - each having its own shared memory area?
  • 0

#4 Pete Dowson

Pete Dowson

    Advanced Member

  • Moderators
  • 27,355 posts
  • LocationNear Stoke-on-Trent, UK

Posted 10 August 2012 - 12:04 PM

Is it possible to have multiple instances of FSUIPC executing at the same time - each having its own shared memory area?


You could, but not using the library, because the FSUIPC_Open, will, each time, try to open the same shared memory area. The C source is provided, however, so you can make your own interface code with each thread creating its own memory mapped file with a unique name.

I realy don't see the point, though. Why would you want to do such things? The most efficient way of interfacing to FSUIPC, for both your program and for FS performance, is to do a single regular FSUIPC_Process once per period, with that period being at most frequent something similar to the FS frame rate.

A single specialised thread doing the FSUIPC operations and storing the data for the other threads is surely the most efficient. I would hope you are not considering each of your threads doing individual FSUIPC_Processes for individual reads or writes? That is extremely inefficient. Remember, each time you call FSUIPC_Process you are forcing Windows to transfer control back and forth between processes, an immense waste of time if done needlessly.

Regards
Pete
  • 0

#5 mgh

mgh

    Advanced Member

  • Members
  • PipPipPip
  • 68 posts
  • LocationUK

Posted 10 August 2012 - 05:14 PM

I'm not sure why i might want to do it either, but i've run two instances of FSUIPC in separate loops satisfactorarily.

Each Read/Write statement will have an overhead, but is the overhead on actually transfering data dependent on the volume of data transfered?
  • 0

#6 Pete Dowson

Pete Dowson

    Advanced Member

  • Moderators
  • 27,355 posts
  • LocationNear Stoke-on-Trent, UK

Posted 10 August 2012 - 05:28 PM

I'm not sure why i might want to do it either, but i've run two instances of FSUIPC in separate loops satisfactorarily.


If you mean two "FSUIPC_Open" instances, then both will be using the same Memory Mapped File space so you'd run into trouble if both "loops" wre trying to add Read or Write requests at the same time -- they'd corrupt each others data.

Each Read/Write statement will have an overhead


No, not really any at all. All the Read and Write requests do is add a request to the data. The only call which does anything taking any time is the Process.

but is the overhead on actually transfering data dependent on the volume of data transfered?


Not normally, and certainly not compared to the inherent transaction time, that of sending the message, switching processes, processing the message and swapping back again when completed. With most normal data sizes, ranging from a few hundred to a few thousand bytes, there's no data size differences. Anything likely to slow that down will be requests which actually cause some action to be invoked in FS, like saving or loading files or sending weather requests off and waiting for results.

You can experiment with data sizes and so on quite easily using FSInterrogate, from the SDK. You can actually select the entire set of offset, nearly 64kb, and have it transfer a short intervals. The main thing then slowing things down is its display updating, not the transfers so much.

Regards
Pete
  • 0

#7 mgh

mgh

    Advanced Member

  • Members
  • PipPipPip
  • 68 posts
  • LocationUK

Posted 10 August 2012 - 06:49 PM

If you mean two "FSUIPC_Open" instances, then both will be using the same Memory Mapped File space so you'd run into trouble if both "loops" wre trying to add Read or Write requests at the same time -- they'd corrupt each others data.


i used the published code from the SDK to create a C++ class and then converted it to a Borland C++ component. I dragged and dropped two components into my application and put each in a separate timer loop, running at different speeds. Each loop returned the expected values.
  • 0

#8 Pete Dowson

Pete Dowson

    Advanced Member

  • Moderators
  • 27,355 posts
  • LocationNear Stoke-on-Trent, UK

Posted 10 August 2012 - 08:13 PM

i used the published code from the SDK to create a C++ class and then converted it to a Borland C++ component. I dragged and dropped two components into my application and put each in a separate timer loop, running at different speeds. Each loop returned the expected values.


If the timer loops were in the same thread there's no problem with sharing the same memory space for the accumulated requests as the Read ad Write requests cannot overlap. You were asking about threads were you not?

Pete
  • 0

#9 mgh

mgh

    Advanced Member

  • Members
  • PipPipPip
  • 68 posts
  • LocationUK

Posted 10 August 2012 - 09:00 PM

I wasn't talking about threads - only if more than one instance of FSUIPC can co-exist.
  • 0

#10 Pete Dowson

Pete Dowson

    Advanced Member

  • Moderators
  • 27,355 posts
  • LocationNear Stoke-on-Trent, UK

Posted 10 August 2012 - 10:49 PM

I wasn't talking about threads .


I'm sorry, but the basis of the entire thread arose from you asking about threads. Remember?

I'm programming with FSUIPC dll, and I'd to use threads


About this, though:

- only if more than one instance of FSUIPC can co-exist


It won't be more than "one instance of FSUIPC". FSUIPC is the DLL running inside FS and there can only be one of those. You just mean FSUIPC open links. And for one process there's only one, no matter how many FSUIPC_Opens you make, UNLESS you change the interface code to alter the name of the Memory Mapped File each time. All you are doing is making multiple uses of the same Memory Mapped File for different loops -- it is only one link to FS. The file name is generated from the Process ID. That is necessary to ensure it is different from those used by other applications running at the same time -- otherwise data from different processes would get mixed up and corrupted.. You'd need to add something different to the name to make more than one.

The only reason the data doesn't get mixed up and corrupted in your case with a single thread but separate loops is that the Read and Write access to the Memory cannot occur simultaneously or overlap -- the single thread runs consecutively, no concurrency. Threads, like Processes, are different.

But there's absolutely no point. This discussion is really futile. You can't make things run any better, only worse! I don't understand why you persist after all I've explained to you.

Regards
Pete
  • 0

#11 mgh

mgh

    Advanced Member

  • Members
  • PipPipPip
  • 68 posts
  • LocationUK

Posted 11 August 2012 - 08:40 AM

I'm sorry, but the basis of the entire thread arose from you asking about threads. Remember?


Leonardo Freschi asked about threads: I asked about running multiple instances. Remember?
  • 0

#12 Pete Dowson

Pete Dowson

    Advanced Member

  • Moderators
  • 27,355 posts
  • LocationNear Stoke-on-Trent, UK

Posted 11 August 2012 - 08:43 AM

Leonardo Freschi asked about threads: I asked about running multiple instances. Remember?


Ah, sorry -- to me, one thread, one subject. I didn't even notice change of author. You don't when answering so many threads per day.

Anyway, all the answers are now provided for both questions.

Regards
Pete
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users


About simFlight - simflight.com - simflight.de - simflight.fr - simflight.nl - simflight.pt - simflight.es - simflight.it - simflight.jp - simrussia.com - simMarket