Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Process sequence  RSS feed

 
Tom Hill
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys, hope you can give me a few ideas where to look to solve this problem:

I have a component that recieves a message.
I have an executor with a method execute() that is called by part of a framework. The execute method waits until the component recieves a message and notifies listeners (eg the executor).

I'm trying to then get the component to wait until the Executor has finished with the message.

Ive tried to use a second wait/notify but i get a race condition, being notified before waiting etc.

Currently im using a rather rubbishy spinlock checking if the executor has finished every 10ms.

I can make changes to the component and the executor but i cant access other parts of the framework im working in .

I assume i need some kind of lock so that each section of code is executed in the sequence described. Do you think some kind of control sequence object would assist?

help!

Tom
 
Warren Dew
blacksmith
Ranch Hand
Posts: 1332
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you clarify what you need? As far as the Executor's thread is concerned, is it finished with the message before it notifies the Component?

If it is, it sounds like you need to synchronize the notification. If the Executor notifies before finishing with the message, maybe it shouldn't.
 
Tom Hill
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well ideally i would like the component to notify the executor to the arrival of a message and then wait for the executor to notify after it has finished executing the message. But sometimes the executor will notify before the component has started waiting because the component's thread has been paused by the jvm.

Cheers.

Tom
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm missing why the executor has to be on another thread at all if we're just going to wait for it. If your main thread starts a new thread or can get ahold of the other thread object it can join():

But we might as well do all the work in the main thread. This has a little threading advantage going on:

This is tougher if your runnable is in a thread pool, cause the threads never really end. Maybe ...

You'll have to imagine the runner locking and unlocking the lock.

Is that close to what you need?
[ August 25, 2005: Message edited by: Stan James ]
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Tom Hill:
...Ive tried to use a second wait/notify but i get a race condition, being notified before waiting etc...


Thats called a bug. You should fix it before you abandon the strategy. And what do you mean by second? whats the first doing?
 
Tom Hill
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like i havent explained very well. This was my attempted structure:



the problem is that the 2nd notify is called before the 2nd wait has started.
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wait and notify are use to tell you to _check_ if conditions are correct to proceed. They should not be used to tell you to proceed in and of themselves.

Component Thread:


Executor Thread
 
Tom Hill
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see!
I was using seperate lock objects to notify and wait but I was using the boolean messageAvaliable/messsageProcessed parameters. I shall give it a go straight away.

Thanks very very very much!

Tom
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!