Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Synchronization in thread
Forum Updated to NodeBB v4.3 + New Features

Synchronization in thread

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 1.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    qtdev
    wrote on last edited by
    #1

    i have two thread running simul.. i want to access a same file from both thread and want to write data in that file..in synchronous manner..plz share code ..

    Thanks in advance..

    1 Reply Last reply
    0
    • G Offline
      G Offline
      guziemic
      wrote on last edited by
      #2

      In my opinion, you could utilize "QMutexLocker":http://qt-project.org/doc/qt-5.0/qmutexlocker.html
      inside write method. There is example how to use it on Qt documentation.

      1 Reply Last reply
      0
      • I Offline
        I Offline
        issam
        wrote on last edited by
        #3

        @QMutex mutex;

        thread1::run()
        {
        mutex.lock();

        // write data to the file

        mutex.unlock();
        }

        thread2::run()
        {
        mutex.lock();

        // write data to the file

        mutex.unlock();
        }

        @

        http://www.iissam.com/

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved