Uncertain results in a non synchronized multithreaded program

1 view
Skip to first unread message

Akash Kothawale

unread,
Sep 18, 2012, 1:56:12 PM9/18/12
to Vedang Manerikar, CodeBreak...@googlegroups.com
Hi, 
The program http://pastebin.com/s4taV7Ns

Thread A writes certain value to var X, prints it and then increments it.
Thread B simply prints the content of var X.

Expected output:
After thread ID A writes to X, X = 0
After thread ID B reads from X, X = 1

Actual output:
// Sometimes 
After thread ID A writes to X, X = 0
After thread ID B reads from X, X = 1

// Sometimes 
After thread ID A writes to X, X = 0
After thread ID B reads from X, X = 0

Thanks & Regards,
Akash
 | Pune Institute of Computer Technology

Vedang

unread,
Sep 19, 2012, 12:47:58 AM9/19/12
to codebreak...@googlegroups.com
Put this program in a git repository called assignments and publish it
to bitbucket (you can have private repos on bitbucket)
/vedang
> --
> You received this message because you are subscribed to the Google Groups
> "Codebreakers Dreamz" group.
> To post to this group, send an email to
> CodeBreak...@googlegroups.com.
> To unsubscribe from this group, send email to
> CodeBreakers-Dr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



--
Unix is simple. It takes a genius to understand it's simplicity. - Anon
People think it must be fun to be a super genius, but they don't
realize how hard it is to put up with all the idiots in the world.
- Calvin.

Cheers,
Vedang.

Programmer,
Infinitely Beta.
http://twitter.com/vedang
http://vedang.me
Reply all
Reply to author
Forward
0 new messages