Can a single threaded application have a deadlock? If so, please provide an example.
Yes, a single-threaded application can deadlock if you have threads that are not re-entrant and a thread attempts to reacquire a lock that it owns already (like via a recursive call).
Edit: I see that the post has been tagged "Java"; I don't know if that was an update or if I missed it before, but in any case locks in Java ARE re-entrant, so you won't be able to deadlock a single-threaded application in this manner.
It depends a little on how you interpret the question. If resources that are shared with other applications are involved, then yes. Without shared resources, no.
A deadlock is a situation wherein two or more competing actions are waiting for the other to finish, and thus neither ever does.
With a single thread, there is only one action, which can't compete with itself.
From Wikipedia:
Necessary conditions
There are four necessary and sufficient conditions for a deadlock to occur, known as the Coffman conditions from their first description in a 1971 article by E. G. Coffman.
- Mutual exclusion condition: a resource that cannot be used by more than one process at a time
- Hold and wait condition: processes already holding resources may request new resources
- No preemption condition: No resource can be forcibly removed from a process holding it, resources can be released only by the explicit action of the process
- Circular wait condition: two or more processes form a circular chain where each process waits for a resource that the next process in the chain holds
By this definition, two processes are required to consitute a deadlock.