Linux.com

Author Message
Joined: Apr 23, 2008
Posts: 15
Other Topics
Posted May 05, 2008 at 3:32:09 PM
Subject: sig_atomic_t to avoid mutex/critical sections

On linux using pthreads, if I have a 2-bytes variable x shared by pthreads used only in the following ways:
(1)
x=value;
(2) or (separately)
if (x==value) {do something (not with x)}
(3) or (separately)
other variable (not shared) = x;

Is it correct to define it
sig_atomic_t x; (no matter if 4 or 2 bytes)
and AVOID to protect every instruction of kind (1) or (2) or (3) with pthread_mutex_lock()/trylock() before and pthread_mutex_unlock() after ?
Can I be sure there is no race condition/unpredicted event/problem?

In a few words: is it correct to speed up a software using sig_atomic_t data instead of mutexed data with the fundamental condition that data are as little as 2-4 bytes and are accessed only in the very simple way above?

Thanks

Back to top Profile Email Website
Shashank Sharma
Joined Jan 01, 1970
Posts: 1452
Location:New Delhi, India

Other Topics
Posted: May 08, 2008 1:45:36 PM
Subject: sig_atomic_t to avoid mutex/critical sections

Not sure if this answers your question:
http://sourceware.org/ml/libc-alpha/2005-07/msg00004.html

But I'll admit, you do ask some tough questions.

Coauthor of Beginning Fedora: From Novice to Professional published by Apress.

Please follow the Forum Guidelines

Back to top Profile Email Website Yahoo!
Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya