File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

another thread question

 
arie zwijnsma
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

suppose 2 threads are concurrently using the same integer m_i.
as in m_i++; or if ( m_i == 1 ) or j = m_i%2==0?m_i:-1
i am wondering are these statements thread safe 'on their own' ???
i mean is it possible that the os switches to the 2nd thread when
the 1st thread has not yet finished the statement it was working on ?
(see also code below)
thanks arie.
 
tvs sundaram
Ranch Hand
Posts: 153
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
volatile.??!!!
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Arie,
I would say that the statements ARE NOT thread safe because it is quite possible for a time-sharing thread handler to remove one thread when its' time is up and it has not completely finsihed the statement. Since thread handling is up to each vendor you can never be completely sure what will happen to threads.
Regards,
Manfred.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic