Skip to content

Commit 9926f0f

Browse files
ifixes #157 @1h
1 parent a60eacc commit 9926f0f

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

include/pthread/sync_queue.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ namespace pthread {
5353
*/
5454
void put (const T& item);
5555

56-
/** Put an item in the queue (wait if size >= max_size).
56+
/** Put an item in the queue.
57+
*
58+
* If the queue size is greater or equal to max_size, then wait for the wiat-time millis for the queue to empty a bit.
5759
*
5860
* @param item item to store in the queue
5961
* @param wait_time millis to wait for the queue to free a slo
@@ -62,13 +64,13 @@ namespace pthread {
6264

6365
/** Get an item from the queue.
6466
*
65-
* If the queue is empty, get waits for an item to be put.
67+
* If the queue is empty, the method blocks until an item is entered in the queue.
6668
*
6769
* @param item item that will receive an item found onto the queue.
6870
*/
6971
void get ( T& item);
7072

71-
/** Get an item from the queue, if empty wait for one during duration milliseconds.
73+
/** Get an item from the queue, if the queue is empty, then wait for an element wait_time milliseconds.
7274
*
7375
* @param item item that will receive an item found onto the queue.
7476
* @param wait_time duration we are willing to wait for a new item.

tests/synchronized_queue_tests.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class producer : public status, public pthread::abstract_thread {
127127

128128
//pthread::this_thread::sleep_for(1*1000);
129129
}
130-
printf("send stop producing message\n");
130+
std::cout << "send stop message" << std::endl;
131131
message_ptr pmessage(new message("stop", -1));
132132
_queue.put(pmessage);
133133
};
@@ -160,8 +160,7 @@ class consumer : public status, public pthread::abstract_thread {
160160
}
161161

162162
if ((100 % counter()) == 0) {
163-
printf("queue's current content is %zu (thrd: %o );\n", _queue.size(),
164-
pthread::this_thread::get_id());
163+
printf("queue's current content is %zu (thrd: %o );\n", _queue.size(), pthread::this_thread::get_id());
165164
}
166165

167166
pthread::this_thread::sleep_for(CONSUMER_PROCESSING_DURATION);
@@ -175,6 +174,7 @@ class consumer : public status, public pthread::abstract_thread {
175174
printf("queue get timed out (%s, at %d)\n", __FILE__, __LINE__);
176175
}
177176
}
177+
178178
printf("stopping consumer\n");
179179
};
180180

@@ -232,7 +232,7 @@ TEST(synchronized_queue, producer_consumer) {
232232
// The + 1 is because we send one more message: a stop message
233233
EXPECT_EQ(MESSAGES_TO_PRODUCE + 1, consumed_messages);
234234

235-
printf("threads joined main program, consumed %d messages (%s, %d)\n", consumed_messages, __FILE__, __LINE__);
235+
std::cout << "threads joined main program, consumed " << consumed_messages << " messages" << std::endl;
236236

237237
pstatus = EXIT_SUCCESS;
238238
} catch (std::exception &err) {

0 commit comments

Comments
 (0)