Skip to main content
Home
for DLMS smart meters
Open source solutions for DLMS smart metering

Main navigation

  • Home
  • Products
  • About us
  • Open Source
  • Community
  • Forum
  • Downloads
User account menu
  • Log in

Breadcrumb

  1. Home
  2. Forums
  3. Use Gurux.dlms.cpp In Multi-threaded Environment

Use gurux.dlms.cpp in multi-threaded environment

Forum Rules

Before commenting read Forum rules

Don't comment the topic if you have a new question.

You can create a new topic selecting correct category from Gurux Forum and then create a new topic selecting "New Topic" from the top left.

By jan.kolar , 7 March, 2018
Forums
Gurux.DLMS

I am integrating gurux.dlms.cpp library into our application which will be simultaneously reading register values from multiple meters. Typically this application will be used for communication with 20 meters but it is possible that number of meters will be 40 or 60. We want meter readout to be as fast as possible therefore we use multiple threads, one thread for each meter / comport. In every thread I am creating separate instances of CGXDLMSClient & CGXCommunication classes. Is gurux library thread-safe ? While browsing through source codes & debugging I found that binary data are saved to "trace.txt" text file. This is done in following static function:

void GXHelpers::Write(std::string fileName, std::string data)
{
if (data.size() != 0)
{
std::ofstream trace;
trace.open(fileName.c_str(), std::ios::out | std::ios::app);
trace.write(&data[0], data.size());
trace.close();
}
}

There is not any thread synchronization present (like mutex or critical section), I think this is mistake. I want to ask if there are another possible places of thread synchronization problems in gurux library that need to be taken in consideration ?

Profile picture for user Kurumi

Kurumi

8 years 3 months ago

Use gurux.dlms.cpp in multi-threaded environment

Hi Jan,

You need to create own instance from each CGXDLMSClient for each thread. CGXCommunication is only example to read one client. Gurux.DLMS.cpp don't write anything, so that does not cause any problems.

You need to check the communication part. I believe that you are using TCP/IP connection. If you are you need to create own session for each part.

BR,

Mikko

  • Create new account
  • Reset your password

Hire Us!

Latest Releases

  • Tue, 06/09/2026 - 11:16
    gurux.dlms.java 4.0.95
  • Tue, 06/09/2026 - 10:03
    Gurux.DLMS.Python 1.0.199
  • Mon, 06/08/2026 - 13:39
    gurux.dlms.cpp 9.0.2606.0801
  • Mon, 06/01/2026 - 10:15
    gurux.dlms.cpp 9.0.2606.0101
  • Thu, 05/28/2026 - 16:06
    gurux.dlms.java 4.0.94

New forum topics

  • Error reading L&G Meter
  • Pass a TCP Client to GXNet
  • Australian EDMI Mk10D (Essential Energy area)
  • Strange mix of data notificiation vs get response
  • DLMS Connection
More

Who's new

  • Tuanhgg
  • Adel
  • charnon
  • Paddles
  • Miguel Ángel
RSS feed
Privacy FAQ GXDN Issues Contact
Follow Gurux on Twitter Follow Gurux on Linkedin