This is the mail archive of the
gdb@sources.redhat.com
mailing list for the GDB project.
Re: shared variable
- To: Nicolas Vignal <nicolas dot vignal at netline dot fr>
- Subject: Re: shared variable
- From: Fernando Nasser <fnasser at cygnus dot com>
- Date: Wed, 07 Feb 2001 11:51:01 -0500
- CC: gdb at sources dot redhat dot com
- Organization: Red Hat , Inc. - Toronto
- References: <01020715255000.00952@nicolas>
Nicolas Vignal wrote:
>
> Hello
>
> I know that shared variable must be lock. But behaviour of software under
> debugger and reality should be the same.
Not really. There is timing involved and debuggers introduce "artifact". Results can be unpredictably different.
> If you try this little code under
> the last linux gdb snapshot you will see a difference.
>
> On console I have :
>
> I create the thread number 1026
> I am the thread number 1026
>
> Under gdb :
>
> I am the thread number -1
> I create the thread number 1026
>
> Regards
>
> Nicolas
>
> #include <stdio.h>
> #include <pthread.h>
>
> pthread_t threadID=-1;
>
> int function(void)
> {
> printf("I am the thread number %d\n",threadID);
>
> while (1);
>
> return 0;
> }
>
> int main(int argc, char *argv[])
> {
>
> pthread_create(&threadID, NULL, function, NULL);
> printf("I create the thread number %d\n",threadID);
>
> return 0;
> }
--
Fernando Nasser
Red Hat - Toronto E-Mail: fnasser@redhat.com
2323 Yonge Street, Suite #300
Toronto, Ontario M4P 2C9