This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Racing Condition
- From: Hei Chan <structurechart at yahoo dot com>
- To: "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
- Date: Wed, 19 Dec 2012 23:16:05 -0800 (PST)
- Subject: Racing Condition
- Reply-to: Hei Chan <structurechart at yahoo dot com>
Hi,
Let's say I have 2 threads trying to call the function below without any synchronization:
void func(int x) {
??? static char buffer[512];
??? sprintf(buffer, "%d\n", x);
??? printf(buffer);
}
since buffer is static, and so obviously in some cases, there will be 2 threads trying to write to buffer, 1 writing to buffer and another reading from it, or 2 reading from it.
Since it is just an array of char, besides content/stdout might not be what the callers should be expecting; will it cause the program to crash.
Thanks in advance.
Cheers,
Hei