deadlocked code | Bytes (2024)


deadlocked code | Bytes (1) 19 New Member

For some reason i am unable to compile or execute the following code ...look like a i have a deadlock or something like that ...

Could anyone send me into the right direction ? Thanks !!
This is the code:

Expand|Select|Wrap|Line Numbers

  1. intitemCount
  2. procedureproducer(){
  3. while(true){
  4. item=produceItem()
  5. if(itemCount==BUFFER_SIZE){
  6. sleep()
  7. }
  8. putItemIntoBuffer(item)
  9. itemCount=itemCount+1
  10. if(itemCount==1){
  11. wakeup(consumer)
  12. }
  13. }
  14. }
  15. procedureconsumer(){
  16. while(true){
  17. if(itemCount==0){
  18. sleep()
  19. }
  20. item=removeItemFromBuffer()
  21. itemCount=itemCount-1
  22. if(itemCount==BUFFER_SIZE-1){
  23. wakeup(producer)
  24. }
  25. consumeItem(item)
  26. }
  27. }

Oct 30 '07 #1

Subscribe Reply

4 deadlocked code | Bytes (2) 2150 deadlocked code | Bytes (3)


1,275 deadlocked code | Bytes (5) Recognized Expert Top Contributor

For some reason i am unable to compile or execute the following code ...look like a i have a deadlock or something like that ...

Could anyone send me into the right direction ? Thanks !!
This is the code:

int itemCount

procedure producer() {
while (true) {
item = produceItem()

if (itemCount == BUFFER_SIZE) {

putItemIntoBuff er(item)
itemCount = itemCount + 1

if (itemCount == 1) {
wakeup(consumer )

procedure consumer() {
while (true) {

if (itemCount == 0) {

item = removeItemFromB uffer()
itemCount = itemCount - 1

if (itemCount == BUFFER_SIZE - 1) {
wakeup(producer )

consumeItem(ite m)

Please use code tqags while posting ur code.
U wint get a deadlock problem when compiling ur code.
Why there are no semi colons(;) in the code.
First tell me, whether ur code is compiling?


Oct 31 '07 #2



19 deadlocked code | Bytes (6) New Member

No unfortunately my code does not compile .

Oct 31 '07 #3



4,677 deadlocked code | Bytes (8) Recognized Expert Moderator Specialist

So what errors are you getting?

Oct 31 '07 #4



3,652 deadlocked code | Bytes (10) Recognized Expert Specialist

Is this even C or C++? If it is, then you are missing semicolons everywhere. If not, then this is the wrong forum for this post.

Oct 31 '07 #5


Sign in to post your reply or Sign up for a free account.

Similar topics

51 5252


by: Mudge |last post by:

Please, someone, tell me why OO in PHP is better than procedural.


9 3858

FrontController Design Pattern and Code Reuse

by: bigoxygen |last post by:

Hi. I'm using a 3 tier FrontController Design for my web application right now. The problem is that I'm finding to have to duplicate a lot of code for similar functions; for example, listing users, and listing assignments use similar type commands. Is there a "better" way I can organize my code?


4 2426

somewhat painful join code

by: jason |last post by:

Hello. Newbie on SQL and suffering through this. I have two tables created as such: drop table table1; go drop table table2; go

Microsoft SQL Server

16 3099

Strange behaviour of simple code

by: Dario de Judicibus |last post by:

I'm getting crazy. Look at this code: #include <string.h> #include <stdio.h> #include <iostream.h> using namespace std ; char ini_code = {0xFF, 0xFE} ; char line_sep = {0x20, 0x28} ;

C / C++

1 2374

ExecuteXmlReader deadlocked exception; new to framework 1.1

by: Adam Smith |last post by:

When executing ExecuteXmlReader() against a table where records are being inserted, I get: 9/5/2003 8:39:47 AM Transaction (Process ID 66) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction. at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream) at System.Data.SqlClient.SqlCommand.ExecuteXmlReader()

C# / C Sharp

1 1672

aspnet_wp.exe (PID: 1864) was recycled because it was suspected to be in a deadlocked state. It did not send any responses for pending requests in the last 180 seconds.

by: bmmodi |last post by:

Hello, We have three webservers that host the same web application (written in VB.NET running on .NET Framework 1.0 SP2). We receive the following error (aspnet_wp.exe (PID: 1864) was recycled because it was suspected to be in a deadlocked state. It did not send any responses for pending requests in the last 180 seconds.) every few days on ONLY ONE of the three servers. At the point when the error occurs, the CPU locks up at 100%. ...


2 2829

aspnet_wp.exe in a deadlocked state

by: Antonio Concepcion |last post by:

Hi! We have an ASP.NET web site experiencing errors saying that aspnet_wp.exe got into a deadlock state and was recycled. Specifically the Client browser gets the following message: ***************************** Server Application Unavailable The web application you are attempting to access on this web server is currently


6 1445

Dumping the state of a deadlocked process

by: andre.naess |last post by:

Hi all I'm currently having some issues with a process getting deadlocked. The problem is that the only way I can seem to find information about where it deadlocks is by making a wild guess, insert a pdb.set_trace() before this point, and then step until it locks up, hoping that I've guessed right. The frustrating part is that most of the time my guesses are wrong.


18 6841

multiple threads writing to WebBrowser, getting deadlocked

by: Zytan |last post by:

I have multiple threads writing to WebBrowser (using a function that checks InvokedRequired, and if so, invokes itself on the WebBrowser thread) and they are getting deadlocked. They only deadlock when I use lock { } around the call to WebBrowser.Write to ensure thread safety! Does any one have experience with such a thing? Zytan

C# / C Sharp


What is ONU?

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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...



Changing the language in Windows 10

by: Hystou |last post by:

Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...

Windows Server


Problem With Comparison Operator <=> in G++

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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...

C / C++


Maximizing Business Potential: The Nexus of Website Design and Digital Marketing

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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...

Online Marketing

1 8371

The easy way to turn off automatic updates for Windows 10/11

by: Hystou |last post by:

Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...

Windows Server


Discussion: How does Zigbee compare with other wireless protocols in smart home applications?

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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...



Couldn’t get equations in html when convert word .docx file to html file in C#.

by: conductexam |last post by:

I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...

C# / C Sharp


Trying to create a lan-to-lan vpn between two differents networks

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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...

Networking - Hardware / Configuration


Windows Forms - .Net 8.0

by: adsilva |last post by:

A Windows Forms form does not have the event Unload, like VB6. What one acts like?

Visual Basic .NET

deadlocked code | Bytes (2024)


How do you avoid deadlocks in code? ›

To circumvent the deadlock problem, it is recommended that you need to sort the information to be accessed in a certain order before grabbing locks. Deadlock refers to a specific condition in a database, when two processes are waiting for the other process to release a resource.

How do you clear a deadlock? ›

A deadlock is resolved by aborting and restarting a process, relinquishing all the resources that the process held. This technique does not limit resource access or restrict process action.

How to fix deadlock in Java? ›

Java provides various methods to avoid thread deadlock, such as using synchronized blocks, using thread-safe collections, and using atomic operations.
  1. Using Thread. join() ...
  2. Using Synchronization Objects. ...
  3. Avoid Nested Locks. ...
  4. Avoid Using Locks When Not Needed. ...
  5. Proper Design of Code.
Jan 20, 2023

How to fix deadlock in C++? ›

In our case, the deadlock happens when two threads are waiting for a mutex owned by the other. One of the most common ways of avoiding a deadlock is to always lock the two mutexes in the same order. If we always lock mutex A before mutex B, then we'll never have a deadlock.

What is the simplest way to avoid a deadlock? ›

Timeouts: To avoid deadlocks caused by indefinite waiting, a timeout mechanism can be used to limit the amount of time a process can wait for a resource. If the help is unavailable within the timeout period, the process can be forced to release its current resources and try again later.

What is the best way to deal with deadlocks? ›

Best Practices for Deadlock Handling

Avoid Resource Contention: Design your applications and systems in a way that minimizes resource contention. This includes proper resource allocation, releasing resources in a timely manner, and avoiding unnecessary resource dependencies.

How can deadlock be resolved? ›

A deadlock is broken by aborting and restarting a process, releasing all resources held by the previous process. When using the deadlock detection and recovery method: There would be no restriction on resource access or process execution. When possible, processes are given requested resources.

How deadlock can be recovered? ›

4 Deadlock Recovery

There are two main strategies for doing this: process termination and resource preemption. Process termination means that the operating system kills one or more processes involved in the deadlock and releases their resources.

How to avoid deadlock in Java for a sample code example? ›

Avoid waiting indefinitely: You can get deadlock if two threads are waiting for each other to finish indefinitely using thread join. If your thread has to wait for another thread to finish, it's always best to use join with maximum time you want to wait for thread to finish.

What are the 4 ways to solve deadlock? ›

4. Deadlock Prevention
  • 4.1. No Mutual Exclusion. It means more than one process can have access to a single resource at the same time. ...
  • 4.2. No Hold and Wait. ...
  • 4.3. Removal of No Preemption. ...
  • 4.4. Removal of Circular Wait.
Mar 18, 2024

How can deadlock be prevented? ›

Techniques such as resource allocation ordering, resource allocation graphs, and bankers' algorithm can help prevent deadlocks by carefully managing resource allocation and avoiding circular wait.

What is an example of a deadlock? ›

In a database, a deadlock is a situation in which two or more transactions are waiting for one another to give up locks. For example, Transaction A might hold a lock on some rows in the Accounts table and needs to update some rows in the Orders table to finish.

How can deadlocks be prevented? ›

Deadlock prevention can be achieved by breaking one or more of the necessary conditions. Techniques such as resource allocation ordering, resource allocation graphs, and bankers' algorithm can help prevent deadlocks by carefully managing resource allocation and avoiding circular wait.

What are 3 ways of handling deadlocks? ›

There are three strategies for deadlock handling: deadlock prevention, deadlock avoidance, and deadlock recovery1 [321]. In deadlock prevention, resources (channels or buffers) are granted to a packet in such a way that a request never leads to a deadlock.

What is the simple rule for avoiding deadlocks? ›

One of the simplest ways to avoid deadlocks is to always acquire resources in a specific order. If your processes needs both resource A, and resource B, then always acquire your resources in the same order.

What is the deadlock avoidance method? ›

17.3 Deadlock Avoidance

Whenever any process requests for one or more resources, the system decides if the request can be satisfied immediately or the process should wait, based on the prior knowledge about the needs of all the other processes.

Top Articles
Latest Posts
Article information

Author: Golda Nolan II

Last Updated:

Views: 6498

Rating: 4.8 / 5 (58 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Golda Nolan II

Birthday: 1998-05-14

Address: Suite 369 9754 Roberts Pines, West Benitaburgh, NM 69180-7958

Phone: +522993866487

Job: Sales Executive

Hobby: Worldbuilding, Shopping, Quilting, Cooking, Homebrewing, Leather crafting, Pet

Introduction: My name is Golda Nolan II, I am a thoughtful, clever, cute, jolly, brave, powerful, splendid person who loves writing and wants to share my knowledge and understanding with you.