473,490 Members | 2,472 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Creating multi-threaded code to break locked/wait state

Hi,

If I make a call to function which is in external library, and it goes
into wait sate.. disabling my app to proceed further, how can I break
this state elegantly? So far, I had to kill my process.

Someone suggested to code multi-threaded app in which one can monitor
other and if one goes into locked state, other kills it.

It sounds okay, but I don't know how to do it. Any code sample or
resources you can point me to, will be a great help!

Thanks a lot!!
Nayan

Dec 19 '06 #1
5 1842
JS
I'm going to guess that you're calling this external library to get
some data when it becomes available. I'm also going to guess that as
soon as data is available the call will return from the waiting state.
My suggestion would be to put the call to the external library function
in a thread. When the call returns, put the relevant data into a queue
for other thread(s) to read.

Nayan wrote:
Hi,

If I make a call to function which is in external library, and it goes
into wait sate.. disabling my app to proceed further, how can I break
this state elegantly? So far, I had to kill my process.

Someone suggested to code multi-threaded app in which one can monitor
other and if one goes into locked state, other kills it.

It sounds okay, but I don't know how to do it. Any code sample or
resources you can point me to, will be a great help!

Thanks a lot!!
Nayan
Dec 19 '06 #2
Nayan <cn****@gmail.comwrote:
If I make a call to function which is in external library, and it goes
into wait sate.. disabling my app to proceed further, how can I break
this state elegantly? So far, I had to kill my process.

Someone suggested to code multi-threaded app in which one can monitor
other and if one goes into locked state, other kills it.

It sounds okay, but I don't know how to do it. Any code sample or
resources you can point me to, will be a great help!
Well, while using another thread would let you abort the thread,
killing the process is a safer bet. If the external library has hung in
some way or other, you should regard the process as essentially
unstable. Simply aborting a single thread could leave other threads
created by the library, or resources unreclaimed etc.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 19 '06 #3
The scenario is that the external lib function is reading from remote
server. If the server is unable to respond, then my app (being
synchronous call), gets hung.
Killing the process is "okay" solution, though its not the fault of my
app.

JS has assumed correctly all the things.
I liked the idea of JS. I'll try to follow it.
>>Simply aborting a single thread could leave other threads created by the library, or resources unreclaimed etc.
True, but then its better to kill a thread than aborting the whole flow
of application. Threads can be managed if the dependency is low between
them.
Any further suggestions? Thanks for all the efforts :)

Regards,
Nayan

Dec 20 '06 #4
"Nayan" <cn****@gmail.comwrote in message
news:11*********************@f1g2000cwa.googlegrou ps.com...
The scenario is that the external lib function is reading from remote
server. If the server is unable to respond, then my app (being
synchronous call), gets hung.
The lib function should time-out if the remote server is not able to respond, but it should
not let there caller hang indefinitely. So the only real solution is fix this code.
Killing the process is "okay" solution, though its not the fault of my
app.

JS has assumed correctly all the things.
I liked the idea of JS. I'll try to follow it.
>>>Simply aborting a single thread could leave other threads created by the library, or
resources unreclaimed etc.

True, but then its better to kill a thread than aborting the whole flow
of application. Threads can be managed if the dependency is low between
them.
No, it's not, because you can't abort a *managed* thread that is currently executing or
blocking in unmanaged code., all you can do is call Win32's "TerminateThread" API through
PInvoke and terminate the OS thread associated with the CLR thread, but doing this is
dangerous and should only be done when you know precisely what the thread was currently
doing (in unmanaged code), that is, you need at least an answer to the following question
(among others):
- what locks is the thread currently holding?
Most of the time (if not always), you can't answer this question, which leaves you with only
one option: kill the process.

Willy.
Willy.

Dec 20 '06 #5
That's terrible. I mean, I didn't design the external lib, so I can't
control the behaviour of the functions.

If that code cannot be fixed, what should I do? Move to another lib? It
also takes long to change the code.

*Sigh* Is there no alternative except killing my proc? :(

Nayan

Dec 20 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2029
by: tmb | last post by:
I want to have some games in an application I'm considering. I see game creation stuff on the web... anything best suited for Java... or written with Java? Of course, we could do 'em from...
10
2022
by: *ProteanThread* | last post by:
since a majority of people are still on dial up or at most DSL (though there *IS* broadband) does it help or hurt one's webpage adding multi media ? does it necessarily distract from the theme of...
1
2245
by: James | last post by:
I am creating a system whereby equipment is inspected. Data is inputted into an inspection form. However, any equipment that is not satisfactory needs to have spare parts ordered for that piece of...
5
5698
by: bobwansink | last post by:
Hi, I'm relatively new to programming and I would like to create a C++ multi user program. It's for a project for school. This means I will have to write a paper about the theory too. Does anyone...
2
9916
by: Dino | last post by:
I need to create a public multi-dim array that can hold a mixture of string and int values. I will need to search this array for a value and return a value from a subscript. This array will...
4
2502
by: gdarian216 | last post by:
I am doing a multi file program and I got it to work correctly in a single file but when I split it up it isn't working properly. I keep getting errors when i compile. Can anyone help me figure out...
4
4810
by: crescent_au | last post by:
Hi all, I'm doing some research online on creating php-based multi-level marketing (MLM) system. It seems like a complicated system to build as I need to create one from scratch. I'd like to...
1
2281
by: hardieca | last post by:
Hi, I'm building a multi-lingual CMS. The user can add as many languages as he likes. The user will be able to create sections for different content (General, News Releases, etc...) in the db...
3
2391
by: Nathan Sokalski | last post by:
I am looking to create a multi-column list that is scrollable, kind of like a ListBox control, only I need a way to align the columns of text that I will have (I would use spaces, but because the...
1
1599
by: sony.m.2007 | last post by:
Hi, Is there any way of creating a properties file for storing key value pairs in C#.Net? Thanks Sony
0
7112
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7146
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7183
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7356
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4878
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3074
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1389
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
277
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.