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

  • Home
  • SEARCH
  • 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 4607378
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:41:42+00:00 2026-05-22T00:41:42+00:00

I have a linux multithread application in C++. In this application in class App

  • 0

I have a linux multithread application in C++.
In this application in class App offer variable Status:

class App {
...
typedef enum { asStop=0, asStart, asRestart, asWork, asClose } TAppStatus;
TAppStatus Status; 
...
}

All threads are often check Status by calling GetStatus() function.

inline TAppStatus App::GetStatus(){ return Status };

Other functions of the application can assign a different values to a Status variable by calling SetStatus() function and do not use Mutexes.

void App::SetStatus( TAppStatus aStatus ){ Status=aStatus };

Edit: All threads use Status in switch operator:

switch ( App::GetStatus() ){ case asStop: ... case asStart: ... };
  1. Is the assignment in this case, an atomic operation?
  2. Is this correct code?

Thanks.

  • 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-05-22T00:41:43+00:00Added an answer on May 22, 2026 at 12:41 am

    There is no portable way to implement synchronized variables in C99 or C++03 and pthread library does not provide one either. You can:

    • Use C++0x <atomic> header (or C1x <stdatomic.h>). Gcc does support it for C++ if given -std=c++0x or -std=gnu++0x option since version 4.4.
    • Use the Linux-specific <linux/atomic.h> (this is implementation used by kernel, but it should be usable from userland as well).
    • Use GCC-specific __sync_* builtin functions.
    • Use some other library that provides atomic operations like glib.
    • Use locks, but that’s orders of magnitude slower compared to the fast operation itself.

    Note: As Martinho pointed out, while they are called “atomic”, for store and load it’s not the atomic property (operation cannot be interrupted and load always sees or does not see the whole store, which is usually true of 32-bit stores and loads) but the ordering property (if you store a and than b, nobody may get new value of b and than old value of a) that is hard to get but necessary in this case.

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

Sidebar

Related Questions

We have a Linux server application that is comprised of a number of open-source
We have a Linux application that makes use of OpenSSL's Python bindings and I
I have a Linux C++ application and I'd like to test an object pointer
I have a multithreaded Linux application written in C/C++. I have chosen names for
I have a single-threaded linux app which I would like to make parallel. It
I have a multithread linux program which uses epoll(7). The epoll(7) man page says
I have a linux console application - a scientific simulation program that I use.
I have this working fine from Linux command line: wkhtmltopdf entry.html output.pdf But the
I have a Linux app which must spawn a child process on request with
This is a bit confusing. I have a linux executable that I do not

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.