# Window freezes after 4 imshow() updates

**URL:** <https://forum.opencv.org/t/window-freezes-after-4-imshow-updates/18054>\
**Category:** C++\
**Tags:** mingw\
**Created:** [June 23, 2024, 9:44am UTC](https://forum.opencv.org/t/window-freezes-after-4-imshow-updates/18054 "2024-06-23T09:44:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![DRx](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/drx/32/10690_2.png) [@DRx](https://forum.opencv.org/u/DRx)\
**Post date:** [June 23, 2024, 9:44am UTC](https://forum.opencv.org/t/window-freezes-after-4-imshow-updates/18054/1 "2024-06-23T09:44:54Z")

</div>

# System Information

OpenCV version: 4.9.0  
Operating System / Platform: Windows 10 x64  
Compiler & compiler version: MinGW GCC 7.3.0  
OpenCV python version: 4.9.0.80  
Python version: 3.9.6

# Issue

I try to show image/stream video to window using openCV but this window freezes after exactly 4 updates. No matter what language I use: cpp/python/go, result always is the same. This problem appears on 2 different windows machines.  
Result of code execution:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/d/d21c62128c1a8d9ab01c602be576dfcd341533b9.jpeg)  
Cpp code:

```cpp
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>

using namespace cv;
using namespace std;
int main()
{
    std::string image_path = samples::findFile("pic.png");
    cv::Mat image = cv::imread(image_path, cv::IMREAD_COLOR);

    for(;;) {
        cout << "x\n";
        cv::imshow("Output Window", image);
        cv::waitKey(1);
    }

    return 0;
}

```

Python code:

```python
import cv2

video = cv2.VideoCapture(0)
address = "https://192.168.0.23:8080/video"
video.open(address)

while(1):
    print("x\n")
    check, frame = video.read()
    cv2.imshow("zcx", frame)
    k = cv2.waitKey(1) & 0xFF
    if k == 27:
        break

```

Before that I had this build error (here openCV has another version, but I have this error on any version):

```auto
C:\opencv\opencv-4.8.1\modules\core\src\parallel.cpp: In function 'int cv::getThreadNum()':
C:\opencv\opencv-4.8.1\modules\core\src\parallel.cpp:804:25: error: invalid cast from type 'pthread_t' {aka 'ptw32_handle_t'} to type 'void*'
  804 | return (int)(size_t)(void*)pthread_self(); // no zero-based indexing
      | ^ ~~~~~~~~~~~~~~~~~~~~
mingw32-make[2]: *** [modules\core\CMakeFiles\opencv_core.dir\build.make:1003: modules/core/CMakeFiles/opencv_core.dir/src/parallel.cpp.obj] Error 1
mingw32-make[1]: *** [CMakeFiles\Makefile2:3854: modules/core/CMakeFiles/opencv_core.dir/all] Error 2
mingw32-make: *** [Makefile:165: all] Error 2

```

I fixed this error by this steps:

1. change `(int)(size_t)(void*)pthread_self();` on line 804 to `(int)(size_t)pthread_self().p;` in open parallel.cpp
2. changed `posix_thread(0)` on line 218 to `posix_thread()` in parallel\_impl.cpp
