Results 1 to 14 of 14

Thread: Thread Synchronization Problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2009
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Thread Synchronization Problem

    will Mutex or semaphore can do this job

  2. #2
    Join Date
    Nov 2009
    Location
    Siauliai, LT
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Thread Synchronization Problem

    mutex or semaphore can lock data being modified by thread, so the answer is - it depends on what you want to do.
    I came. I saw. I clicked.

  3. #3
    Join Date
    Nov 2009
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Thread Synchronization Problem

    i tried with mutex but not working...
    Unfortunately not getting any feasible solution...

    Thanks 4 helping me

  4. #4
    Join Date
    Nov 2009
    Location
    Siauliai, LT
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Thread Synchronization Problem

    to find a solution you need to know a problem, yet in this thread there is only you who knows what the problem is if you would be so kind to describe it maybe I or anybody else on this forum could provide a solution to your problem. Mutex can only lock your data for reading, writing or reading writing, yet it does not affect any other thread execution in any way if it does not require to read, write or read-write the same data. so you can not be sure that your threads are executed in sync (that is main idea of threads - be apart), so you can not see where you can put use for mutex in your task. from what you have written it seems that you don't need to use threads at all, or simply check thread status wheather is it running or not, or maybe you should check QFuture out?
    Last edited by lonepsycho; 13th November 2009 at 14:27.
    I came. I saw. I clicked.

  5. #5
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Thread Synchronization Problem

    @sijithjames
    Several things:

    - Your code makes very little sense.
    At least I, still can't make out what it is you want to achieve.
    Maybe if you state the objective of your code, or your task,we might help you.
    I have the feeling it doesn't even have to be threaded.

    - Your code shows that you do not understand how threads work in general, and what a mutex is used for, and I think you have even less idea how QThread should be used (there are some points you have to pay attention to when you using QThread, specially thread affinity)

    - On one hand, you are using threads, on the other you state that the problem is that:
    Now what happening is both object is calling hte run function but calling order we cant predict.. Each time its calling in different order
    So it seems you want to have sequential execution order, not parallel execution.
    For sequential excution you don't need threads!


    Also, the fact you see the printf() output not in a sequential way, doesn't mean that they are not called sequentially.
    It could be very well, that for many reasons, the order of printf() calling, and the output you see is not same.

    I suggest you start with the basics, and read about threaded programming, and QThread.
    Probably most of your problems will be solved that way.


    And please use the code tags for posting code, its very hard to read code like that.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Problem with threads
    By kvnlinux in forum Newbie
    Replies: 7
    Last Post: 21st August 2009, 17:29
  2. postEvent thread problem
    By jhamers in forum Qt Programming
    Replies: 1
    Last Post: 5th March 2008, 10:36
  3. Replies: 11
    Last Post: 7th July 2006, 13:09
  4. Thread Problem
    By qball2k5 in forum Qt Programming
    Replies: 2
    Last Post: 12th April 2006, 17:31
  5. Problem building Qt4.1.0 with thread support on windows XP
    By pavithra in forum Installation and Deployment
    Replies: 1
    Last Post: 1st April 2006, 11:35

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.