| | |
Testing whether function is interruptable or not
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jan 2009
Posts: 35
Reputation:
Solved Threads: 1
Hi, experts.
I want to test whether (third library) function (say X) is interruptible or not.
For this, I want to create two threads one for calling function X, the other for interrupting (sending signal) to the first one while it's inside the function X. But I don't know the exact time to interrupt.
Since X, is library function I can't change it in any way.
Is there any kind of ideas regarding this interesting problem?
Thanks.
I want to test whether (third library) function (say X) is interruptible or not.
For this, I want to create two threads one for calling function X, the other for interrupting (sending signal) to the first one while it's inside the function X. But I don't know the exact time to interrupt.
Since X, is library function I can't change it in any way.
Is there any kind of ideas regarding this interesting problem?
Thanks.
What you describe happens all the time with almost every function, and it isn't a problem.
Perhaps you mean the alternative of where T2 tries to call X(), while T1 is already in X().
That's re-entrancy, and is a far more interesting problem.
And no, you can't just "test" to see if a function is re-entrant by calling it a bunch of times from two threads, and seeing what happens.
Perhaps you mean the alternative of where T2 tries to call X(), while T1 is already in X().
That's re-entrancy, and is a far more interesting problem.
And no, you can't just "test" to see if a function is re-entrant by calling it a bunch of times from two threads, and seeing what happens.
•
•
Join Date: Jan 2009
Posts: 35
Reputation:
Solved Threads: 1
Hi,
Thanks for you quick reply.
I think I couldn't explain my problem correctly.
T1 is calling X(), I want to send a signal to T1 when it's inside the function X(), not before calling it nor after calling it. So my objective is to test whether I'm able to receive signals inside X() or not. Even if this is always the case (it's always possible to receive the signal), which I believe is not, I want just to be able to interrupt T1 exactly inside X(). The only purpose of T2 is to send signal to T1 while T1 is inside X(). Besides that T2 doesn't have to do anything.
I hope I'm more clear now.
Thanks.
Thanks for you quick reply.
I think I couldn't explain my problem correctly.
T1 is calling X(), I want to send a signal to T1 when it's inside the function X(), not before calling it nor after calling it. So my objective is to test whether I'm able to receive signals inside X() or not. Even if this is always the case (it's always possible to receive the signal), which I believe is not, I want just to be able to interrupt T1 exactly inside X(). The only purpose of T2 is to send signal to T1 while T1 is inside X(). Besides that T2 doesn't have to do anything.
I hope I'm more clear now.
Thanks.
Last edited by NeoKyrgyz; Jan 6th, 2009 at 4:20 pm.
Unless X() takes a substantial amount of time to execute, it's going to be hard to time a signal.
But something like this for T1 (in a loop)
- release semaphore
- call X()
- get semaphore
And for T2 (in a loop)
- get semaphore
- generate signal
- release semaphore
But if you've got a dual-core machine and an OS that can really distribute threads over processors, then it might produce some results.
But something like this for T1 (in a loop)
- release semaphore
- call X()
- get semaphore
And for T2 (in a loop)
- get semaphore
- generate signal
- release semaphore
But if you've got a dual-core machine and an OS that can really distribute threads over processors, then it might produce some results.
•
•
Join Date: Jan 2009
Posts: 35
Reputation:
Solved Threads: 1
•
•
•
•
Unless X() takes a substantial amount of time to execute, it's going to be hard to time a signal.
But something like this for T1 (in a loop)
- release semaphore
- call X()
- get semaphore
And for T2 (in a loop)
- get semaphore
- generate signal
- release semaphore
But if you've got a dual-core machine and an OS that can really distribute threads over processors, then it might produce some results.
How about following solution:
I don't know the properties of pthread_attr_t, but is it possible to solve this problem by the help of pthread_attr_t? What I mean is, let T1's start routine to be X() and tell by the help of attr1 to spend much time or don't exit inside the X().
main(){
....
pthread_create (T1,attr1,X,arg)
pthread_create (T2,attr,start_routine,arg)
....
}
Last edited by NeoKyrgyz; Jan 7th, 2009 at 12:15 pm.
![]() |
Other Threads in the C++ Forum
- Previous Thread: Builder cpp 6 - resources problem
- Next Thread: Error C2440 and C2504
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






