Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9197783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:08:46+00:00 2026-06-17T22:08:46+00:00

I have 2 scenarios where I don’t know whether I should use QMutex or

  • 0

I have 2 scenarios where I don’t know whether I should use QMutex or not.
I have run the program without QMutex many times & it hasn’t shown me any abnormal behaviour. I have skimmed down the code here for simplicity.
But still as a safe side I would like to know whether I should use QMutex or not?

Scenario #1:

 class A : QObject
 {
    Q_OBJECT

    private double **array;//it is initialised in the constructor & is 100x100

    slots:
          slot1(); //2 Qthreads are created in my main GUI thread along with 2 objects of class A, & by A aobj.movetothread();
          slot2(); //& connecting these 2 slots to started() SIGNAL of respective QThread's
                   //I have multi-threaded my application.
 }

 A::slot1()
 {
    double temp = array[i][j];
    //some operations on temp
 }

 A::slot2()
 {
    double temp = array[i][j];
    //some operations on temp
 }

NOTE: The contents of array[][] are not changed after initialisation. I am only accessing the information from it in the 2 threads. However sometimes the same element from array maybe accessed by both threads simultaneously!

Scenario #2

 A::slot1()
 {
    double temp = somefunc();
    array[0][j] = temp;
 }

 A::slot2()
 {
    double temp = somefunc();
    array[50][j] = temp;
 }

NOTE: In this case, the 2 threads modify elements from the same array, however they don’t modify/access common elements i.e. thread1 deals with say first 50 rows while thread2 deals with next 50 rows, however they don’t even access rows of each other.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:08:47+00:00Added an answer on June 17, 2026 at 10:08 pm

    if those scenarios doesn’t run together, you need no mutex. accessing the data for read from two of threads are ok, modifying different elements from the same array in two (or even more threads) are ok too. the cases where you need mutex is either when two thread modifies the same element from array, or if you modify same elements from one thread while reading them from another one

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several advanced scenarios I would like to solve, but I don't know
We have 18 databases that should have identical schemas, but don't. In certain scenarios,
I have two distinct scenarios. One, where there is a many to many case,
I don't have much knowledge about Windows Phone 7 development. I know there exist
I have writing a multi threaded code. I am not sure, whether I would
When using simple DTOs in various scenarios I have frequently run into the same
I have came across many resources which talk about using/not using multiple assertions during
I have a suite of scenarios that should be runned against a site. Now
I know there is the SecureString class, but for most scenarios I don't think
A few test scenarios have been recorded using CodedUI test template for my web

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.